Using delegation inheritance to copy features to another model
The third type of inheritance is Delegation inheritance. Instead of _inherit
, it uses the _inherits
class attribute. There are cases where, rather than modifying an existing model, we want to create a new model based on an existing one to use the features it already has. We can copy a model’s definitions with prototype inheritance, but this will generate duplicate data structures. If you want to copy a model’s definitions without duplicating data structures, then the answer lies in Odoo’s delegation inheritance, which uses the _inherits
model attribute (note the additional s
).
Traditional inheritance is quite different from the similarly named concept in object-oriented programming. Delegation inheritance, in turn, is similar, in that a new model can be created to include the features from a parent model. It also supports polymorphic inheritance, where we inherit from two or more other models.
...