Skip to Content
Menu
This question has been flagged

I am trying to understand how to modify a given field. Say "default_code" for a "product_template".

I want to modify "default_code" field of "product_template" in a custom method of "product_product". I have the "id" value of the  "product_template" item I want to modify.

I am sure it is fairly basic and easy but I am still learning the basics.

How do you recover the right product_template object having its ID and how do you change default_code to FOOBAR?

Avatar
Discard
Best Answer

Hi E.M,

Actually 'default_code' field which you are trying to update/modify does not exist in "product_template", inspite it is in "product_product" object.

In the same way first you have to identify the object of the given field to modify and then get its record id and simply use write method to modify the field's data.

So if you are having id of 'product_template' object then you can search the corresponding 'product_product' id using "product_tmpl_id" field at product_product master and finally update the value of 'default_code' field using write method of product_product.

Avatar
Discard
Author

Thanks, this works. An additional question puzzles me, if default_code is part of product_product, why when using debug mode in the GUI you see "default_code" for object "product.template" instead of "product.product"?

Its a nice question E.M, this is happening because of a concept called "Delegation Inheritance/instance inheritance" in odoo, where the derived class inherits all the fields of super class but in its "table"(derived class) only new fields added will be stored, however, other inherited fields also can be accessed from the code for the derived object normally. Since, it is inheriting those fields so it can also be used in your views easily. But as its not being stored in corresponding derived table/object at database, you have to go to super class if you want to manually manipulate its value. You can find further details here: Delegation Inheritance

Related Posts Replies Views Activity
6
Oct 15
7835
1
May 19
2566
3
May 19
8634
3
Mar 17
12307
1
Oct 15
2340