Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

How to pass a default value in a treeview ? Odoo.sh V15

Avatar
odoo
Avatar
Discard
3 Answers
0
Avatar
odoo
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
0
Avatar
odoo
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".



4 Comments
Avatar
Discard
Avatar
odoo
-

Thx Dental,

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

Avatar
odoo
-

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

Avatar
odoo
-

Ok thanks Olaf,

Is it possible to make that with Studio?

Denis

Avatar
odoo
-

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

0
Avatar
odoo
Best Answer

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


1 Comment
Avatar
Discard
Avatar
odoo
-

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.