Home › Curriculum › Technical Foundations › Classes, inheritance, decorators and comprehensions
Python for Odoo · 16 min · Python 3.12Classes, inheritance, decorators and comprehensions
Object-oriented Python as Odoo uses it: classes, attributes, methods, super(), decorators and comprehensions.
In this lesson
- Classes, self and super()
- Decorators and Odoo's API decorators
- Comprehensions and recordset equivalents
Key points
- Odoo models are classes inheriting models.Model
- Override = call super() and return its result
- @api.depends, @api.constrains, @api.onchange, @api.model, @api.model_create_multi
- mapped, filtered, sorted; | & - on recordsets
Real-world example
A developer overrode action_confirm without returning super()'s result. Confirming from the form worked, but a website flow expecting an action dictionary broke silently. Adding 'return res' fixed it, and the team added 'always return super()' to their code-review checklist.
Questions and answers
What does filtered() take?
A function (often a lambda) returning truthy for records to keep, or a field name string.
What is a decorator?
A function that wraps another function to change or extend its behaviour.