Home › Curriculum › Odoo Developer › Computed fields, related fields, onchange and constraints
The ORM · 18 min · 17–20Computed fields, related fields, onchange and constraints
@api.depends computations, store and search, inverse, related fields, onchange, Python and SQL constraints.
In this lesson
- Computed fields, store and search
- Inverse, related and display names
- Onchange versus compute, and constraints
Key points
- @api.depends + assign every record; store=True to search/group
- inverse for editable computes; related for path shortcuts
- Prefer computed (readonly=False) over onchange
- @api.constrains raises ValidationError; DB constraints via models.Constraint (19+)
Real-world example
A non-stored computed 'margin %' on sales orders couldn't be grouped in a pivot, so the director's report was empty. Making it stored with correct @api.depends on line costs and prices fixed the report; a migration recomputed it for 60,000 historical orders overnight.
Questions and answers
How do you make a related field groupable?
store=True.
What replaced name_get in Odoo 17+?
_compute_display_name (display_name computed field).