Greetings everyone, in this blog-post, you will learn how to override write method in Odoo 8.
The write method for a particular modelÂ can beÂ called byÂ clicking the ‘Edit’ & followed by ‘Save’ button in the view of that model.
Here i have overridden the write method of res.users model. You can override the write method of any model in similar way in Odoo 8.
You can overrride the write method for a particular model by,
class res_users(models.Model): Â Â _inherit ='res.users' @api.multi Â Â def write(self,vals): print 'Fields and the values to be updated/written--',vals #Write your logic here res = super(res_users, self).write(vals) #Write your logic here return res
You need to give the class name in the super method. For eg here:- res_users
Use of Write Method in Odoo:
- Write method executes an SQL update query on the records.
- The values of the field Â that are going to be wrriten can be found in the vals dictionary, which is the parameter to the method.
- The values can be extracted form the dictionary and can be checked against a criteria and a Warning can be raised if its fails to do so.
- The vals dictionary can be modified as per the requirement before calling the super method.
- The vals will be a blank dictionary if no field is changed.
- If you need to call write method again inside the write method, you need to call super method twice.
Here is a snapshot form eclipse IDE:-
Hope you got an insight and understanding of the ORM write method in Odoo 8 and the way of overriding it.
Please Comment below if you have any doubts,