In this article you will learn how to override Odoo methods. I will show you how to override Odoo Create, Write and Unlink method. Here the question is why we need to override these (create, write and unlink) methods.


Why Override Create, Write and Unlink Method in Odoo


The answer is to add or remove additional functionality we use overriding. For example if I want to check some constraints before creating, editing or deleting our record than we may use Odoo override methods.

Read More: How to Create and Use Function in Python

There are basically three methods which we can override.
  1. Create
  2. Write
  3. Unlink

How to Override Create Method

The create method invoke every time when we click on "Create" or "New" button on Odoo form view and when we save the from using Save button.

Read More: How to Remove Save Button From Form View in Odoo

override_create_function.py



override_write_function.py



override_unlink_function.py


Code Description:

In above code we have a "your_model" class and we have override your_model class create, write or unlink method. 

What is @api


@api.model is a decorator that decorate a record style method. Notice here to override you should call super() method. 

Super method takes two parameter the first one is the name of class which is "your_model" and the second one is "self". Where self is a record set in which model the record is created. Values are dictionary that contains data which we are going to create, write or unlink.