Skip to Content
Menu
This question has been flagged
3 Replies
1198 Views

Hello,

I want to have a tab to fill the default BOM.

How can I have, when I add a line to have "Parent Product Template" automatic filled with my product?


Denis

Avatar
Discard
Best Answer

Hi, 

In your One2many field, add attribute context like this: 

name="O2M" context={'default_X': active_id}

X is your Parent product_template technical name.


hope this helps.

Avatar
Discard
Author Best Answer

Thx Ibrahim for you reply, but that doesn't work (I try with Studio):


Avatar
Discard

I don't see where the context i mentioned was added if your screens.. and i don't know how to add context with studio..
But it's working once it's done.
You can do it via Developer Mode though.

Best Answer

For v15.0+:
In this case the product_template field seems to be the foreign key - if submitted as default-value passed with your context it will be written when the new record is saved. (see https://github.com/odoo/odoo/issues/82366). 

So in this case you should think about a dedicated form to enter new records instead of list-editing. Just define your view like e.g.:


Or it may be easier in the Studio to use "edit form".



Avatar
Discard
Author

Thx Dental,

I think that there is missing words in your reply...

Hi Denis,

what part is not clear to you?

Basically for 15.0 or later it is impossible to pre-set a key-value (reference to parental record). The reference will be automatically set when saving the new child-record when not changed in the edit-form.

For our modules this made it necessary to duplicate each form (we do not edit/create inline) and remove the field "parent_id" so it could not be changed by accident.

Many greetings
Olaf

Author

Ok thanks Olaf,

Is it possible to make that with Studio?

Denis

I'm not familiar with the Studio so I can only guess based on your screenshot. Try the "edit form view" button.