I have inherited some model. I need also to override it's write method.
I've tried this:
@api.multi
def write(self, vals, context=None):
res = super(WebSiteSupportTicket, self).write(vals)
date = datetime.datetime.now()
if vals['state_id']:
if vals['state_id'] == 7 or vals['state_id'] == 8:
vals['closing_date'] = date
print(vals)
return res
Where closing_date is a Datetime field.
When I make the change of state_id to the state with id 7 or 8, closing_date is still being null. But I know the code is passing through the if statement because I can see closing_date on the print of vals
First time I run into a problem with write method. Why is happening and how can I get a solution?
You added the closing_date
to the values dict after you called super
, the closing_date
will not be written.
Remove the context
argument from the function definition (not needed). You can find an example where they override the invoice write method in account module.
Example:
@api.multi
def write(self, values):
# Define the closing_date in values before calling super
if 'state_id' in values and values['state_id'] in (7, 8) :
values['closing_date'] = datetime.datetime.now()
return super(WebSiteSupportTicket, self).write(values)