Blog
Customize Odoo Without Forking: Inheritance Patterns
How to customize Odoo with inheritance and extension modules instead of editing core code, so upgrades stay cheap. Patterns, pitfalls and a decision table.
- mid
- odoo
The short answer
Never edit Odoo’s core files. Put every change in a separate custom module that extends existing models, views and methods through Odoo’s inheritance mechanisms. The core stays untouched, so you can upgrade it, and your changes ride along as a small, reviewable layer on top.
A fork, meaning a modified copy of Odoo’s own code, feels faster on day one. It becomes expensive the first time you need a security patch or a version upgrade, because every change you made has to be found and merged by hand. Inheritance avoids that.
Why upgrades are the real cost
Odoo’s own upgrade documentation is blunt about it: a database with custom modules cannot be upgraded until a version of those modules exists for the target Odoo version. On Odoo.sh, the source code of your installed custom modules has to be current with the target version before the upgrade can run.
So the size and cleanliness of your custom code decides how painful each upgrade is. A small module that extends models in the standard way usually needs modest adjustments. A forked core, or a module that rewrites large chunks of standard behavior, can mean a mini re-implementation project every time.
The three inheritance mechanisms
Odoo’s ORM reference describes the model-level options. In practice you will use these:
| Pattern | What it does | Typical use |
|---|---|---|
Extension (_inherit with no new _name) | Modifies an existing model in place: new fields, new methods, overridden methods | Add a field to sales orders, change validation logic |
Classical inheritance (_inherit plus a new _name) | Creates a new model that copies the parent’s structure | A new document type that resembles an existing one |
Delegation (_inherits or delegate=True on a Many2one) | New model exposes the parent’s fields but stores them on a linked parent record | A new entity that is also a partner or product |
Most customization is the first row. As the ORM reference puts it, when _name is not set, _inherit names a single model to extend in place.
A minimal extension looks like this:
from odoo import fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
delivery_window = fields.Char(string="Delivery window")
Install the module and the field exists on sale.order. Nothing in core was edited.
Overriding behavior safely
When you change what a method does, the Odoo server framework tutorial gives two rules worth tattooing on the team:
- Always call
super(), except in a few specific cases. In the docs’ words, “It is very important to always call super() to avoid breaking the flow.” - Return data consistent with the parent method. If the parent returns a dict, yours must too.
class SaleOrder(models.Model):
_inherit = "sale.order"
def action_confirm(self):
for order in self:
if not order.delivery_window:
raise UserError("Set a delivery window before confirming.")
return super().action_confirm()
The same tutorial advises using an @api.ondelete method to control deletion rather than overriding unlink() directly. That keeps your rule out of the way of module uninstalls and other internal operations.
One more habit: override at the narrowest point possible. If you can hook a small helper method instead of a large public one, do that. Every line of standard logic you copy into an override is a line that can silently drift from the standard in the next version.
Extending views without replacing them
Screens follow the same principle. You do not edit the standard XML view. You create an inheriting view that points to the parent with inherit_id and selects where to apply a change, typically with an XPath expression or a field reference, and a position such as inside, before, after, replace or attributes. The view reference covers the syntax.
Practical advice:
- Prefer
afterorinsidewith a field anchor overreplace. Replacing a block means you now own that block, and the next version may change what surrounds it. - Use
attributesto hide or make a field required instead of deleting it. - Anchor to stable elements such as named fields, not to positional paths like “the third group”. Positional paths break when a minor release reshuffles the layout.
What counts as a fork in disguise
Teams that say they are not forking sometimes still are. Warning signs:
- Copying a core module into your repository and editing it. This is a fork, even if the folder has a new name.
- Overriding a large method and pasting in the whole original body with small edits.
- Patching Odoo’s files on the server during deployment.
- Using
replaceon large view sections, or on whole templates.
If a customer asks for something that really does require changing the heart of a standard workflow, say so plainly and weigh it. Sometimes the right answer is to change the process, not the software.
Use community modules before writing your own
Before building, check whether someone already solved it. The Odoo Community Association (OCA) is a non-profit that, by its own description, maintains thousands of open source Odoo modules and open upgrade paths. Their modules follow shared conventions and are often built as small inheritance layers, which is the style you want.
Trade-offs to be honest about: OCA modules are community-maintained, so quality and version coverage vary by module. Check the target version branch, recent activity and test coverage before depending on one. If you adopt a module, pin it and treat it as a dependency you will review at upgrade time.
A practical checklist
- Put all changes in custom modules, kept in version control, separate from core.
- Keep each module small and single-purpose, so you can drop or rewrite one without touching the rest.
- Call
super()and keep return types consistent. - Extend views with anchored XPath and field references, not wholesale replacement.
- Write automated tests for the behaviors you override, so an upgrade tells you what broke.
- Document why each customization exists. In two years, nobody will remember.
- Run an upgrade rehearsal on a copy of your database before you commit to a date. Odoo’s docs describe requesting an upgraded test database while you adapt custom code in parallel.
- Ask for each request: could configuration, a standard setting or a no-code tool do this instead? The cheapest customization is the one you do not write.
When customization is the wrong tool
Heavy customization is a choice with a recurring cost. If a requirement touches only one team, appears once a quarter, or can be handled with an export and a spreadsheet, it may not deserve code that you will then carry through every upgrade. Keep a short list of “custom things we own” and review it before each major version.
Talk it through
If you are planning Odoo customizations, or you inherited a system you suspect is a fork, we are happy to look at it with you. Teknologia Solutions offers a no-charge conversation to review your approach, flag upgrade risks and suggest where inheritance, configuration or community modules can replace custom code. No pressure, and no obligation.
Sources: Odoo upgrade documentation; Odoo ORM reference; Odoo server framework 101, chapter 12: Inheritance; Odoo views reference; Odoo Community Association; OCA maintainer-tools wiki. Documentation links point to the 18.0 docs; details differ between Odoo versions, so verify against the official documentation for the version you run.