Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
11741 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
paź 22
3775
8
lut 17
8298
0
sty 17
5856
2
lut 24
12519
5
maj 24
25181