In-place Model extension
Our first task is to add the is_available
Boolean field to the Book Model. For this, we will use the classic, in-place, Model extension. The value for this field could be automatically computed, based on the book borrow and return transactions, but for now, we will keep it as a simple field.
To extend an existing Model, we will use a Python class with an _inherit
attribute, thus identifying the Model to be extended. The new class inherits all of the features of the parent Odoo Model, and we only need to declare the modifications we want to introduce. These modifications will also be available everywhere else this Model is used. We can think of this type of inheritance as getting a reference for the existing Model and making in-place changes to it.
Adding fields to a Model
New Models are defined through Python classes. Extending Models is also done through Python classes, with help from an Odoo-specific inheritance mechanism, that is, the _inherit
class attribute. This...