Embedding models using delegation inheritance

Delegation inheritance is less frequently used, but it can provide very convenient solutions. It is used through the _inherits attribute (note the additional "s") for dictionary mapping inherited models with fields linking to them.

A good example of this is the standard user's model, res.users; it has a partner model embedded in it:

from odoo import fields, modelsclass User(models.Model): 
    _name = 'res.users' 
    _inherits = {'res.partner': 'partner_id'} 
    partner_id = fields.Many2one('res.partner') 

With delegation inheritance, the res.users model embeds the inherited model, res.partner, so that when a new User class is created, a partner is also created and a reference to it is kept in the partner_id ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.