Adding a new field to an existing model
Our first task is to add the is_available
Boolean field to the book model. For now, this will be a simple editable field, but at a later stage, we can imagine changing it to be automatic, based on books that have been borrowed and returned.
To extend an existing model, we must use a Python class with the _inherit
attribute, identifying the model being extended. The new class inherits all of the features of the parent Odoo model, and we only need to declare the modifications to introduce. We can think of this type of inheritance as getting a reference for the existing model and making in-place changes to it.
Adding new fields with the in-place model extension
Extending models is done through Python classes by using the Odoo-specific inheritance mechanism that's declared using the _inherit
class attribute. This _inherit
class attribute identifies the model to be extended. The declared calls capture all the features of the inherited...