Home › Curriculum › Odoo Developer › Inheritance: extension, prototype and delegation; overriding methods
Business logic and automation · 16 min · 17–20Inheritance: extension, prototype and delegation; overriding methods
The three inheritance mechanisms, overriding create, write, unlink and business methods correctly.
In this lesson
- Three inheritance mechanisms
- Overriding create, write, unlink and hooks
- MRO and why copying core code is dangerous
Key points
- _inherit (extension) for most customisations
- _name + _inherit (prototype) for new models with shared behaviour
- _inherits (delegation): res.users → res.partner
- super() + return; @api.model_create_multi; @api.ondelete; override narrow hooks
Real-world example
A module copied the whole _prepare_invoice method to add one field. When Odoo changed that method's internals in a minor update, invoices lost their fiscal position silently. Replacing the copy with a super() call that added the field to the returned dict fixed it and survived the next upgrade.
Questions and answers
What does @api.ondelete(at_uninstall=False) do?
Runs a check before unlink that's skipped when the module is being uninstalled.
Which model uses delegation to res.partner?
res.users (and others like res.company).