Odooers论坛

欢迎!

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


0

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

形象
odoo
形象
丢弃
3 答案
0
形象
odoo
最佳答案

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.

形象
丢弃
0
形象
odoo
最佳答案

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 注释
形象
丢弃
形象
odoo
-

Thx Dental,

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

形象
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

形象
odoo
-

Ok thanks Olaf,

Is it possible to make that with Studio?

Denis

形象
odoo
-

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

0
形象
odoo
最佳答案

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


1 备注
形象
丢弃
形象
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.