In Odoo 18, inheritance enables seamless customization of modules, from data models and views to methods and interfaces. This slide outlines the different types of inheritance techniques for extending functionality effectively.
Enterprise
In Odoo 18,inheritance enables seamless customization of
modules, from data models and views to methods and
interfaces. This slide outlines the different types of inheritance
techniques for extending functionality effectively.
Introduction
3.
Enterprise
The two typesof inheritance in Odoo are,
1- Model Inheritance
2- View Inheritance
Types of Inheritance
4.
Enterprise
Odoo offers threemain types of model inheritance:
1) Delegation
2) Extension
3) Classical inheritance.
Model Inheritance
Enterprise
In Odoo, whenboth the `_inherit` and `_name` attributes are
used together, the new model builds upon the existing model
specified by `_inherit`. This allows the new model to inherit all
the fields, methods, and metadata (such as defaults) from the
base model.
Classical Inheritance
Enterprise
In the codeabove, two classes are defined: a parent class and a
child class.
The parent class only specifies the `_name` attribute, while the
child class defines both `_name` and `_inherit`. This allows the
child model to inherit the fields and functions of the parent
class.
Let’s now see how this works in practice:
Explanation
9.
Enterprise
In this way,the child model can access the data, fields, and
functions of the parent model.
10.
Enterprise
When using theextension form of inheritance, only the _inherit
attribute is needed, without the _name attribute. This replaces
the original model with the new one, while allowing us to add
more fields or functionalities to the existing model. Below is an
example of how to implement extended inheritance:
Extension
Enterprise
When we inspectthe database, we can see that the field
`description` has been added to the model
`extension.extension`.
We use the _inherits attribute for delegation inheritance. This
type of inheritance allows you to link another model to your
current model without altering the views. As a result, the
database tables will contain both a field for the inherited object
and the data from your model.
Below is an example of how to implement delegation
inheritance:
Delegation
Enterprise
In Odoo, wecan observe that the product template contains
several `many2one` fields in the product model. Odoo
provides multiple examples of this setup. These fields are
stored exclusively in the product template table, although the
product model can access and use the fields from the product
template.
Delegation
15.
Enterprise
● View inheritancein Odoo lets child views extend base
views without replacing them. Using inherit_id, extension
views can add or remove elements via XPath components
in the arch field.
● In other words, these extensions allow you to add or
remove elements from the parent view
View Inheritance
Enterprise
We can examineeach attribute used for view inheritance:
1. XPath Tag Within the `arch` Field:
`expr="//page[@name='hr_settings']"`: This XPath expression
targets a specific element within the original view.
2. Position:
This attribute determines the placement of the field,
specifying whether it should be added before, after, or replace
the targeted element.
Xpath Attributes
Enterprise
Inheritance in Odoo18 enhances development by promoting
code reusability and maintainability. It allows extending models
and views efficiently while ensuring consistent updates across
the application.
Conclusion
21.
For More Info.
Checkour company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com