This question has been flagged
1 Reply
9028 Views

Hi Odoo developers.

Which situations is the delegation inheritance mechanism useful in?.

Avatar
Discard
Author

Thanks Akhil. A very good answer.

Best Answer

Hi,

    The delegation inheritance inherits only fields and methods are not inherited. It can be useful, when we need to embed a model in our current model without affecting the existing views, but we want to have the fields of inherited objects.

    Any field not found in current model will be taken from the inherited models. You can have multiple inheritance, so that the new table created in DB contains your new fields and fields which delegates the inherited object fields (fields storing IDs from inherited tables.


You can find an example in hr.py in hr module:


class hr_employee(osv.osv):

_name = "hr.employee"

_description = "Employee"

_order = 'name_related'

_inherits = {'resource.resource': "resource_id"}

.................

.................

columns{

'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True, auto_join=True),


}

Here hr.employee objects inherits resource.resource object by delegation and all fields of resource.resource object are accessible from hr.employee. For each employee a resource record will be created and its foreign key is stored in resource_id. The fields values of resource.resource synchronized with the hr.employee object.

Refer the link also: https://www.odoo.com/documentation/8.0/reference/orm.html#inheritance-and-extension


Avatar
Discard

But in this case, do I have to build all the views manually from scratch? Is there a way to say to Odoo "use the original exiting views of the main module, and do the following modifications"? I mean like the basic class inheritance. As you know, basic Class Inheritance uses the same main views because the new module name is actually typical to the main module. But in prototype & delegation it has different name.