How to Inherit and Extend Modules in Odoo

Odoo is one of the most flexible ERP platforms available today. One of its strongest features is the ability to inherit and extend modules without modifying the original code. This ensures cleaner development, better upgrade compatibility, and easier customisation.

In this article, we’ll walk through the concepts, methods, and steps to inherit and extend modules in Odoo.

Why Inherit Modules?

When working with Odoo, you’ll often need to adapt existing functionality to meet business requirements. Instead of editing core modules (which can break upgrade compatibility), Odoo allows you to use inheritance.

Key Benefits of Inheritance

  • Keeps core modules untouched.
  • Customizations remain safe during upgrades.
  • Enables modular and reusable code.
  • Allows you to override or extend business logic easily.

Types of Module Inheritance

Odoo provides three main types of inheritance:

1. Model Inheritance

​Used to extend an existing model (e.g., sale.order) by adding new fields or methods.​

      • Example: Add a customer_code field to res.partner.

2. View Inheritance

​Allows you to modify an existing view (form, tree, kanban, report) using inherit_id ​   ​and xpath.​

      • Example: Add a field below partner_id in the Sale Order form.

3. Report/Template Inheritance

​Used to extend QWeb templates (for reports and website views).​

      • Example: Add a company logo or extra fields to an invoice PDF.

Creating a Custom Module Skeleton

Inside your custom addons path, create the following structure:

my_module_inherit/

│── __init__.py

│── __manifest__.py

│── models/

│     └── __init__.py

│     └── sale_order.py

│── views/

│     └── sale_order_views.xml

│── reports/

│     └── sale_report_inherit.xml

Step 1: Define the Manifest File

​Your __manifest__.py should include:

​{

​    'name': 'My Module Inherit',

​    'version': '1.0',

​    'depends': ['sale'],

​    'data': [

​        'views/sale_order_views.xml',

​        'reports/sale_report_inherit.xml',

​    ],

​    'installable': True,

​    'application': False,

​}


Step 2: Model Inheritance (Python)  : 

models/sale_order_inherit.py

​from odoo import models, fields


​class SaleOrderInherit(models.Model):

​    _inherit = "sale.order"


​    customer_code = fields.Char(string="Customer Code")



models/__init__.py

​from . import sale_order_inherit


Step 3: View Inheritance (XML)


​<odoo>

​    <record id="view_order_form_inherit" model="ir.ui.view">

​        <field name="name">sale.order.form.inherit</field>

​        <field name="model">sale.order</field>

​        <field name="inherit_id" ref="sale.view_order_form"/>

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

​            <xpath expr="//field[@name='partner_id']" position="after">

​                <field name="customer_code"/>

​            </xpath>

​        </field>

​    </record>

​</odoo>


Step 4: Install/Upgrade the Module


  1. Place the module inside your addons or custom_addons path.
  2. Restart the Odoo server.
  3. Activate Developer Mode.
  4. Go to Apps → Search for your module → Install.



And that’s it! You’ve successfully inherited and extended an Odoo module. This approach helps you keep your customizations upgrade-safe, clean, and reusable.




Share this post
Tags
Archive
Understanding Software Versioning: What It Means for You