I have a form with a One2many field. From this field you can add elements, if you do this, a pop-up is opened. I would like to know how to get a field which was in the parent form in this pop-up.
For example:
The parent form (model my.parent.model
) has a field named partner_id
. The pop-up (model my.child.model
) has a field named product_id
. In my.child.model
I added a function which is called when product_id
changes (@api.onchange('product_id')
). In this function I want to get the partner_id
selected in the parent form.
To do this, I added this to product_id
in the XML view:
<field name="product_id" context="{'partner_id':parent.partner_id}" />
In the onchange function, if there is not a selected partner, I raise an exception. When the pop-up is opened, this exception always raises, despite having a partner selected. But then, when I select any product, it works perfect.
The problem is that the onchange function is triggered when the pop-up is opened, and in this case the context does not have the variable partner_id
(as if it hadn't had enough time to get it).
This problem did not happened in version 7, because in this version you had to pass variables to the onchange and you can include the partner_id
there, but now, in version 8, how can I manage this?
Thank you in advance!
Ok, I wasted a lot of time looking for a solution without adding new fields to the model, and I've found a solution just one minute after asking my question.
I had to add a context too to the One2many field of the parent form:
<field name="order_line" position="attributes">
<attribute name="widget">"one2many_list"</attribute>
<attribute name="context">"{'partner_id': partner_id}"</attribute>
</field>
Now it works when the pop-up is opened!