Skip to Content

Strategic Model Design: Mastering Odoo Inheritance Patterns

MuhammedMukthar
20 January 2026 by
muktharicap@gmail.com

In Odoo development, inheritance is not merely a feature; it is the fundamental architecture that allows for modularity and scalability. For any professional architect, understanding the nuances of how Odoo handles data relationships through inheritance is critical.

Selecting the correct inheritance pattern ensures that your module remains compatible with future Odoo versions and maintains optimal database performance.

1. Class Inheritance (Extension)

Global Functional Enhancement

Class inheritance is the primary method for modifying the behavior of existing Odoo models. By using the _inherit attribute without a new _name, you perform an "in-place" extension of the model.

  • Database Impact: Odoo performs an ALTER TABLE on the existing database table to add new columns.

  • Strategic Use: Use this pattern when you need to introduce a feature that should be available across the entire ecosystem for that specific entity.

Enterprise Use Case: Automated Logistics Tracking

In a global supply chain project, we needed to implement carbon footprint tracking for every shipment. By extending stock.picking, we ensured that every transfer—be it internal, incoming, or outgoing—inherited the tracking logic and data fields automatically.

class StockPicking(models.Model):
    _inherit = 'stock.picking'

    carbon_footprint = fields.Float(string="Carbon Footprint (kg CO2e)")
    tracking_method = fields.Selection([
        ('standard', 'Standard Calculation'),
        ('iot', 'IoT Sensor Data')
    ], string="Calculation Method")

2. Prototype Inheritance

Structural Replication

Prototype inheritance is used to clone the definition of an existing model into a completely new entity. While the new model inherits all fields and methods, it lives in a separate database table.

  • Database Impact: Odoo creates a brand-new table. There is no data link between the original and the new model.

  • Strategic Use: Use this when you require the sophisticated logic of a standard model (like Project Tasks or Sales Lines) but need the data to remain strictly isolated for a specialized purpose.

Enterprise Use Case: Simulation and Sandboxing

For a financial services client, we required a "Scenario Planner." We inherited from the account.move model to create a "Shadow Ledger." This allowed users to simulate massive financial entries to see the projected impact on their balance sheet without ever touching the actual accounting records.

class AccountMoveShadow(models.Model):
    _name = 'account.move.shadow'
    _inherit = 'account.move'
    _description = 'Financial Scenario Simulation'

3. Delegation Inheritance (Polymorphism)

Composition-Based Modeling

Delegation inheritance allows a model to "embed" another model using the _inherits attribute. This is Odoo’s way of handling "is-a" relationships while maintaining a clean, normalized database structure.

  • Database Impact: Odoo maintains two separate tables. A Many2one field links the child record to the parent record.

  • Strategic Use: This is the ideal pattern for creating specialized roles. It prevents the "God Object" anti-pattern where a single table (like res.partner) becomes bloated with specialized fields that only apply to a few records.

Enterprise Use Case: Healthcare Provider Management

In a Healthcare Management System, we needed a medical.practitioner model. Rather than cluttering the general Contacts table with medical license numbers and specialties, we used delegation. This allowed every Practitioner to act as a Partner (for billing and messaging) while keeping medical-specific data in its own dedicated table.

class MedicalPractitioner(models.Model):
    _name = 'medical.practitioner'
    _inherits = {'res.partner': 'partner_id'}

    partner_id = fields.Many2one('res.partner', required=True, ondelete='cascade')
    medical_license_no = fields.Char(string="Medical License Number", required=True)
    specialty_id = fields.Many2one('medical.specialty', string="Primary Specialty")

Strategic Summary

PatternMechanismDatabase TablePrimary Goal
Class_inheritExisting TableEnhancing global features.
Prototype_name + _inheritNew TableStandalone copy of a feature.
Delegation_inheritsTwo Linked TablesSpecialization without table bloat.


muktharicap@gmail.com 20 January 2026
Share this post
Tags
Archive