Question

What advantage is gained by having product.product inherit from product.template instead of defining all the fields directly in product.product?

_name = "product.product"
_description = "Product"
_inherits = {'product.template': 'product_tmpl_id'}

When would I use this technique in new code?

Was it helpful?

Solution

When using _inherits you will do a kind of polymorphic model in the database way.

For example product.product inherits product.template or res.users inherits res.partner. This mean we create a model that gets the know how of a Model but adds aditional data/columns in a new database table. So when you create a user, all partner data is stored in res_partner table (and a partner is created) and all user related info is stored in res_users table.

To do this we use a dict: _inherits = {'res.partner': 'partner_id'} The key corresponds to the base model and the value to the foreign key to the base model.

From here you can mix inheritance if you dare...

here some links:

http://help.openerp.com/question/46/the-different-openerp-model-inheritance-mechanisms-whats-the-difference-between-them-and-when-should-they-be-used/

https://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/object_inherits/

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top