Reputation: 394
I want to override a write method who's already overrading the same method of the same model.
Original method is like this:
@api.multi
def write(self, values):
if list(values.keys()) != ['time_ids'] and any(workorder.state == 'done' for workorder in self):
raise UserError(_('You cannot modify a close workorder'))
return super(MrpWorkorder, self).write(values)
I need to change the if statement to:
@api.multi
def write(self, values):
if list(values.keys()) != ['time_ids'] and any(workorder.state == 'cancel' for workorder in self):
raise UserError(_('You cannot modify a close workorder'))
return super(MrpWorkorder, self).write(values)
But when I do that, the "super" execute the old content of the method.
So, I need to know how to override an overrided method.
Upvotes: 1
Views: 1016
Reputation: 1
If you want to specify the module that you want to override it's overrided built-in function, follow this:
Import the class (here i am importing the hr.leave class from the hr_holiday module):
from odoo.addons.hr_holidays.models.hr_leave import HolidaysRequest as HRLeavesInherit
then copy the whole function and return this:
result = super(HRLeavesInherit,self).write(values)
HRLeavesInherit < it's not the inherit class name .. So you have to change your inherit class name to be different.
Upvotes: 0
Reputation: 394
In order to do what we need, the solution is more simple than you could think:
Just change the return from this:
return super(MrpWorkorder, self).write(values)
To this:
return models.Model.write(self, values)
With this you override the original method and avoid all the other overrided methods that exist. It's a very special situation when you have to do this, so be careful if you don't want to lose some overrided methods in other modules.
This also work with write and unlink methods.
Upvotes: 1