コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
11728 ビュー

Say I want to make the product_uom field (many2one) of sale.order.line dependent on the field shop_id (also many2one) of sale.order. I choose a shop and I'm allowed to use certain pre-defined product_uom's for that particular shop without saving the sale.order in the process.

How do I make this happen? How can I filter the options of a dropdown based on another field's value?

I have already created the connections between shop_id and product_uom using a many2many field. This would probably be a lot easier if the filtered field was in the same object, but in this case the field to be filtered is in sale.order.line and the "master field" is in sale.order.

I tried an on_change method, but I couldn't figure out how to apply the domain change for a different object's field. I also tried to set the domain of the product_uom field to point to the shop_id's connection field (ie. the many2many field) without success.

アバター
破棄
最善の回答

You are working on v7 or v8? I think you can pass the shop_id in context, to the sale.order.line. And define an onchange function in sale.order.line, on which you can set the product_uom ids to shop_id.uom_ids.

For eg:

in .xml file:

<field name="order_line" context="{'shop_ids': shop_id}"/>

And another way is to use this context value directly in product_uom field domain. Am not sure about this second way, just try. But in onchange you can set the uom_ids I think.

アバター
破棄
最善の回答

Since you already have the many2many relation betwen the shops and the uoms you can add a domain to the uom field of the sale_order_line:

<field name="product_uom" domain="[('id', 'in', [uom.id for uom in order_id.shop_id.uom_ids])]"/>

Hope that helps.

Regards.

アバター
破棄
著作者 最善の回答

René: Since this question site doesn't allow me to comment other questions/answers than my own, I'm gonna just leave this here.

I thank you for taking the time to answer, but I get an immediate JavaScript error when I try your suggestion. Apparently the token parser hangs at the word 'for'. And even if this worked, wouldn't it require me to save sale.order before the filter would be applied to product_uom? I have an itch that somehow the on_change method is necessary here.

アバター
破棄
関連投稿 返信 ビュー 活動
1
10月 22
3771
8
2月 17
8293
0
1月 17
5856
2
2月 24
12517
5
5月 24
25177