Free support 120 Days
Free Support
Free support Mon - Fri From (10 AM - 10 PM) IST
Odoo>Get an Overview of Different Types of Inheritance in Odoo

Get an Overview of Different Types of Inheritance in Odoo

view data

Odoo

view data

5 MIN READ

view data

August 31, 2021

Loading

Inheritance in Odoo

When we use or inherit an old class or model, methods, properties, and views in the new class or model, it is known as Inheritance. This concept relates to Object-Oriented Programming. We extend fields, properties, and views of the existing model in a modular manner for inheritance in Odoo.

During the customization of an Odoo module, there are several situations when we require inheriting some models so as to achieve a specific case. There are multiple inheritances in Odoo, out of which three varieties of model inheritance are primarily supported.

This blog is going to give you information on the technical aspects of these three types of inheritance in Odoo

technical inheritance in Odoo

1. Classical Inheritance

The first type of inheritance in Odoo is the classic inheritance, in which we use both of the _name, as well as _inherit attributes combined. Additionally, the new Odoo models get all fields and methods from their base.

Example:

Classical Inheritance

We can generally check how this is going to work. Nevertheless, we’re going to generate records in both of the models that are done through the following codes.

Here is a test on both of the models:

Odoo model

Moreover, it can easily be understood that every function and field in the parent Odoo model can be accessed anytime from the child Odoo model. In addition to this, the parent models’ fields, methods, etc. here aren’t changed, rather we use the parent models’ features without disturbing their functionality.

2. Extension

While using the extension form of inheritance in Odoo, we will use just the _inherit, and not the _name attribute. Furthermore, the child model substitutes the existing one. Also, this type of inheritance in Odoo is used at the time of adding new methods or fields to the existing Odoo model.

Here is one instance of the command used for adding the extension inheritance:

Extension inheritance

Moreover, while checking the database now, the model will be seen containing the freshly created fields, i.e., the fields in your model will appear as name and description now.

3. Delegation

In the delegation type of inheritance in Odoo, the _inherits attribute is used. In addition to this, this inheritance in Odoo is used when you wish to sink a different model into your existing model without disrupting the views. Thus, the database tables are going to hold fields in your Odoo model along with a field showing the inherited object.

An instance of the command used for adding the delegation inheritance in Odoo is shown below:

Example:

Delegation inheritance

We’ve different examples in Odoo, and here we can notice the product model contains many2one fields along with the product template. Furthermore, the Product model of Odoo can use fields from a Product template whereas the fields contained in the product template get stored only in the product template’s table.

Conclusion

In the above blog, we have discussed multiple inheritances in Odoo. Knowing how to inherit fields in Odoo is very useful during the customization of an Odoo module. For any concerns regarding the process, you can get a thorough consultation with Ksolves experts. Feel free to reach us any time!

Contact Us for any Query

Email: sales@ksolves.com
Call : +91 8130704295
Website: https://store.ksolves.com/

Loading

Need Help