Learn: Overriding Write Method in Odoo 8

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,

 

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:-

Overriding Write Method in Odoo 8

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,

Thank you.

Myself, Burhan Vakharia, am an Odoo developer, CS Lover living in Gandhinagar, Gujarat, India. I have a degree in Computer Science and Engineering from Babaria Institute of Technology. I am currently working as Odoo Developer. Apart from Odoo Framework, I have worked on C# .Net and Android Platforms. You can contact me via my social profiles shown below.

Post Author: Burhan Vakharia

Myself, Burhan Vakharia, am an Odoo developer, CS Lover living in Gandhinagar, Gujarat, India. I have a degree in Computer Science and Engineering from Babaria Institute of Technology. I am currently working as Odoo Developer. Apart from Odoo Framework, I have worked on C# .Net and Android Platforms. You can contact me via my social profiles shown below.

4 thoughts on “Learn: Overriding Write Method in Odoo 8

    parth06007

    (November 27, 2015 - 1:27 pm)

    nice tutorial…good start

    pav19892

    (December 3, 2015 - 6:32 pm)

    Thanks for guide me it is awesome work I wish you could go further and please share with us more information

    abdessamed

    (March 17, 2016 - 1:21 pm)

    Hi,
    Why you used : @api.multi
    Thanx

      Burhan Vakharia

      (April 8, 2016 - 9:40 am)

      @api.multi is for multiple records, where you can loop through it. In Odoo v7 the write method has a parameter called ‘ids’, where a list is passed. In odoo v8, this parameter is decorated with the decorator @api.multi. So now you don’t need to pass ids. You can get the list of ids in v8 by printing ‘self._ids’.

Leave a Reply

Your email address will not be published. Required fields are marked *