Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to modify "default_code" field for a "product_template" provided that you have that "product_template" ID

By
E.M.
on 7/10/15, 1:11 AM 387 views

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?

1

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 7/10/15, 3:15 AM

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.

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"?

E.M.
on 7/10/15, 4:59 PM

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

Pawan
on 7/15/15, 1:11 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/10/15, 1:11 AM
Seen: 387 times
Last updated: 7/10/15, 4:58 PM