Reputation: 3
I am trying to add 30 days in date field in sale.order
in OpenERP v.7
Actualy I did it but the problem is that I want that 30 days to be added on the date I choose in other date field not just to add a 30 days on today's date.
The Date field is date_order
. When I choose a date, I want that 30 days to be added on the chosen date. In the code I make it to add that 30 days on today's date but I want it on the date I am choosing automatically to be changed 30 days later.
class Sale_Order(osv.Model):
_inherit = 'sale.order'
_columns = {
'duedate': fields.date('Duedate', readonly=True),
}
_defaults = {
'duedate': (date.today() + timedelta(days=30)).strftime(DEFAULT_SERVER_DATE_FORMAT),
}
Can someone help me?
Thank you!
Upvotes: 0
Views: 1232
Reputation: 656
For achieve, You need to Make duedate field as compute type
Example:
from datetime import date
from dateutil.relativedelta import relativedelta
Define duedate as compute field
duedate = fields.Date(string='Duedate', compute='_compute_duedate')
Define Compute Function
@api.multi
def _compute_duedate(self):
for rec in self:
rec.duedate = date.today() + relativedelta(months=+1)
Hope this help you.
Upvotes: 0
Reputation: 1623
Sound like you need override create/write methods to change "duedate", if was changed date field. But you can also describe duedate as functional field (stored in table or not).
Method to retrieve date:
def _get_due_date(self, cr, uid, ids, name, args, context=None):
...
Field description:
'duedate': fields.function(_get_due_date, type='datetime', string="Due date"),
Upvotes: 2