Adding features to a Model using inheritance
One of the most important Odoo features is the ability of module addons extending features defined in other module addons without having to edit the code of the original feature. This might be to add fields or methods, modify the existing fields, or extend the existing methods to perform additional logic.
It is the most frequently used method of inheritance and is referred to by the official documentation as traditional inheritance or classical inheritance.
We will extend the built-in Partner model to add it to a computed field with the authored book count. This involves adding a field and a method to an existing model.
Getting ready
We will reuse the my_module
addon module from Chapter 4, Creating Odoo Addon Modules.
How to do it...
We will be extending the built-in Partner model. We should do this in its own Python code file, but to keep the explanation as simple we can, we will reuse the models/library_book.py
code file:
- First, we ensure that the...