Skip to Content
Menu
This question has been flagged
2 Replies
2535 Views

Iam using odoo 13 enterprise 

I have create custom field in both models (product.template & product.product)

when i save data from product form its only save in product.template not in product.product.


Avatar
Discard
Best Answer

Just adding your field to product template will do the job. Don't add it in product_product every product template fields are inherited by product so if you add filed to product_template it will be for every product under the same template. Take product type and product category field in template for example.

Avatar
Discard

This example was very helpful. Thank you for sharing.

Best Answer

Without posting your code, I'm not able to help you but I can give you some information about Odoo inheritance.

Odoo provides three different mechanisms to extend models in a modular way. One of these ways is delegation inheritance which enable you to inherit all fields (Method is not inherited) from parent model to the child model and you can add other new fields to the child model. 

This kind of inheritance used in product.product model which inherit all fields from  product.template model.

So you can add your custom field to product.template only and add it to the product common view (product_template_form_view) which inherited by product.product model. You will be able to use the field from product.product directly. 

Note: In delegation inheritance, the methods of parent model are not inherited So  If you created any method in product.template to change the value of your custom field you need to add them to product.product.

Refer to Odoo documentation:


Avatar
Discard
Author

I have already put the same field in product.produt also but still product.product filed is not getting data.
class productExtend(models.Model):
_inherit = 'product.template'
itempackage = fields.Many2one('item.package', string='Item package')

class productproductExtend(models.Model):
_inherit = 'product.product'
itempackage = fields.Many2one('item.package', string='Item package')

You have to put it in 'product.template' only