Build Dynamic and Editable Odoo Fields
One of Odoo’s most powerful features is its ability to define computed fields. Computed fields allow you to display data dynamically without storing it directly in the database. But sometimes, we need more than just computed values—we need fields that can both calculate and accept manual input. That’s where compute and inverse methods come in.
In this article, we’ll break down how to use these methods effectively, highlight common pitfalls, and walk through real examples to help you build smarter, more responsive fields in Odoo.
What Are Computed Fields?
A computed field is one whose value is automatically calculated based on other fields or business logic. Instead of being entered manually by users, it’s derived.
For example, if you have a sale.order.line model with price_unit and product_uom_qty, you might want a computed field subtotal:
Here, the field subtotal is never entered directly; it’s calculated by the system.
The Compute Method
The compute method defines how Odoo calculates a field.
Example
Key points
- The method is decorated with @api.depends, so Odoo knows when to re-calculate.
- If either price_unit or product_uom_qty changes, Odoo recomputes subtotal.
- With store=True, the value is stored in the database for reporting and searching.
The Inverse Method
By default, computed fields are read-only. But what if you want users to edit them directly
This is where the inverse method comes in. It tells Odoo how to handle manual updates on a computed field.
Example
Now:
- If you change discount_percent, Odoo computes discounted_price.
- If you change discounted_price, the inverse method updates discount_percent accordingly.
This creates a two-way synchronisation between fields.
The Search Method
Sometimes, you might also want users to search based on computed fields. Since Odoo does not always store these fields in the database, you can define a custom search method to make them searchable.
Example
With this setup, users can filter or search for records — for instance, orders with total_amount > 1000 — even though total_amount is a computed value.
Best Practices for Compute and Inverse
Always use @api.depends
Without it, Odoo won’t know when to recompute.
Be careful with recursion
If your compute and inverse methods call each other indirectly, you’ll create infinite loops.
Use store=True wisely
Stored computed fields speed up reporting but add extra database writes.
Add readonly=False
If you want users to edit computed fields, make sure they aren’t read-only in the view.
Inverse is optional
Only define it if users need to edit the computed value.
Key Takeaways
The combination of compute, inverse, and search methods makes Odoo fields incredibly flexible. With these tools, you can:
- Automate calculations across models.
- Allow two-way editing for smarter user experiences.
- Enable search ability even on computed values.
Whether you’re building a payroll system, an approval workflow, or a custom pricing engine, mastering these methods will help you design clean, efficient, and user-friendly modules.