Different Types of Inheritance in Odoo 16

HARSHAD
June 12, 2023

In Odoo 16, a popular open-source ERP system, there are different inheritances that you can use to extend and customize the functionality of existing models. These inheritance types provide flexibility and modularity in Odoo development, allowing you to customize the system to meet specific business requirements. Here are the different inheritances in Odoo 16.

  1. Class Inheritance 

Class inheritance allows you to inherit and extend an existing model class in Odoo. You can define a new class that inherits from the base class and add or override its attributes, methods, and other functionalities. Class inheritance is denoted by the keyword inherit in the model definition.

Payton code:

                                     class NewModel(models.Model):

                                                _inherit = “base. model”

                                                new_field_name = fields.Char()

                                                def new_method(self):

 # Custom implementation

                                                  Pass
  1. Prototype Inheritance

Prototype inheritance enables you to reuse and change existing views and templates in Odoo. You can create a new view or template based on an existing one and customize it as per your requirements. Prototype inheritance is specified using the inherited attribute in the view definition.

XML code:

                       <record id="new_view_id" model="ir.ui.view">

                        <field name="name">new.view</field>

                        <field name="model">base.model</field>

                         <field name="inherit_id" ref="base.view_form"/>

                           <field name="arch" type="xml">

                                 <!-- Customize the view -->

                         </field>

         </record>

  1. Function Inheritance

Function inheritance allows you to extend or change the behavior of an existing function in Odoo. You can create a new function and specify it as an extension of the original function. Function inheritance is accomplished using the @api. multi decorator and the super() method to call the parent function.

DOWNLOAD ERP

Python code:

class NewModel(models.Model):

                               _inherit = 'base.model'



                              @api.multi

                              def existing_function(self):

                                    # Custom implementation

                                    result = super(NewModel, self).existing_function()

                                    # Modify result or add additional functionality

                                    return result
  1. Workflow Inheritance

Workflow inheritance allows you to extend or change the existing workflows in Odoo. You can add new states, transitions, or conditions to an existing workflow or create a new workflow based on an existing one. Workflow inheritance is defined using XML tags such as <record>, <field>, and <workflow>.

XML code:

 <record id="new_workflow_id" model="workflow">

                                                <field name="name">new.workflow</field>

                                                <field name="osv">base.model</field>

                                                <field name="on_create">True</field>

                                                <field name="state">draft</field>

                                                <!-- Customize the workflow states and transitions -->

       </record>
  1. Data Inheritance

Data inheritance allows you to inherit and extend the data defined in another module. You can import and modify existing data records or add new records to extend the functionality of the module. They typically achieve data inheritance by specifying the depend attribute in the module’s manifest file.

XML code:

<record id="new_data_id" model="ir.model.data">

<field name="name">new_data_record</field>

<field name="model">base.model</field>

<field name="module">my_module</field>

<field name="res_id">base.model_id</field>

<!-- Customize the data record -->

</record>

These inheritance types provide powerful mechanisms for extending and customizing Odoo models, views, functions, workflows, and data.

Request Your Free Quote

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

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