How to override a model method in a custom Odoo module?
Overriding a model method in a custom module is a common and powerful practice in Odoo application development. It allows you to extend or customize the business logic without altering the core codebase — which is essential for maintaining upgrade compatibility.
Here’s a quick Odoo Application Development overview of how to do it correctly:
🛠️ Step-by-Step to Override a Method in Odoo
Create your custom module if you haven’t already.
Inherit the model using the _inherit attribute.
Override the method using the same name, and call super() if you want to extend (not replace) the logic.
📦 Example: Overriding the create Method in sale.order
from odoo import models, fields, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.model
def create(self, vals):
# Custom logic before create
vals['note'] = 'This order was modified by a custom module.'
# Call original method
record = super(SaleOrder, self).create(vals)
# Custom logic after create
# e.g., sending notifications, logs, etc.
return record
📌 Best Practices
Always use super() to retain base logic unless you fully intend to override it.
Avoid modifying core models directly.
Use proper naming conventions and module structures.
Test thoroughly when overriding critical methods like create, write, or unlink.
If you're just getting started, I recommend checking the Odoo Application Development overview in the official docs to understand how Odoo’s ORM and inheritance system works.
Let me know if you need help overriding methods like write, unlink, or custom business logic!




https://au88.blue/