5 best practices for developing Odoo modules
Clean code that survives migrations: conventions, tests and structure for maintainable, long-lived Odoo modules.
A custom module can be your best ally or a technical debt that haunts you with every upgrade. The difference lies in following Odoo's conventions and Python best practices.
1. Respect the standard structure
Every module should have a predictable structure: models/, views/, security/, data/, tests/ and a clear __manifest__.py. Consistency lowers maintenance cost.
2. Inherit, don't rewrite
Leverage Odoo's inheritance model instead of duplicating core logic. That way your module keeps working as Odoo evolves.
from odoo import models, fields, api
class SaleOrder(models.Model):
_inherit = "sale.order"
margin_pct = fields.Float(
string="Margin %",
compute="_compute_margin_pct",
store=True,
)
@api.depends("amount_total", "margin")
def _compute_margin_pct(self):
for order in self:
order.margin_pct = (
(order.margin / order.amount_total) * 100
if order.amount_total else 0.0
)
3. Define security from the start
Don't leave permissions for last. Declare ir.model.access.csv and the necessary record rules as soon as you create a new model.
4. Write tests
Odoo ships with an excellent testing framework. A few tests on critical logic will save you hours of debugging and make migrations far safer.
5. Document and version
A good README, clear commit messages and semantic versioning of the module mean anyone —including your future self— can maintain it.
Conclusion
Developing for Odoo isn't just about "working today", but about still working after the next migration. These five practices make the difference between an asset and a liability.
Comments (0)
Be the first to comment.
Sign in to leave a comment.
Sign inComments are reviewed before publishing.
Related articles
Automated actions in Odoo: let the ERP do the boring work
Server actions, automation rules and scheduled jobs: the three pieces that make Odoo react, notify and run on its own —without anyone having to remember.
PDF reports with QWeb in Odoo: from the form to the document that closes deals
QWeb is HTML that turns into PDF. We show you how to build a report, loop over records with t-foreach, and why t-field saves you a thousand headaches.
Inheritance in Odoo: the feature that decides whether your code survives upgrades
Classical extension, delegation and view inheritance. The three ways to modify Odoo without touching the core —and why inheriting instead of copying saves you every migration.