3 答案
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.
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".
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