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.
我有一个One2many字段的表单。在此字段中,您可以添加元素,如果执行此操作,则会打开一个弹出窗口。我想知道如何在弹出窗口中获取父窗体中的字段。
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.
父表单(模型my.parent.model)有一个名为partner_id的字段。弹出窗口(模型my.child.model)有一个名为product_id的字段。在my.child.model中,我添加了一个在product_id更改时调用的函数(@ api.onchange('product_id'))。在这个函数中,我想在父表单中选择partner_id。
To do this, I added this to product_id
in the XML view:
为此,我在XML视图中将其添加到product_id:
<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.
在onchange函数中,如果没有选定的伙伴,我会引发异常。打开弹出窗口时,尽管选择了合作伙伴,但此异常总是会提升。但是,当我选择任何产品时,它都是完美的。
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).
问题是打开弹出窗口时会触发onchange函数,在这种情况下,上下文没有变量partner_id(就好像它没有足够的时间来获取它)。
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?
这个问题在版本7中没有发生,因为在这个版本中你必须将变量传递给onchange,你可以在那里包含partner_id,但现在,在版本8中,我该如何管理?
Thank you in advance!
先谢谢你!
1 个解决方案
#1
3
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:
我不得不在父窗体的One2many字段中添加一个上下文:
<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!
现在它在弹出窗口打开时有效!
#1
3
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:
我不得不在父窗体的One2many字段中添加一个上下文:
<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!
现在它在弹出窗口打开时有效!