Odoo Help


How to make the options of a many2one field depend on another field's value?

Miku Laitinen
on 7/7/14, 9:15 AM 3,144 views

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.


Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 5/8/15, 1:21 AM

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.


René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 7/7/14, 9:30 AM

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.


Miku Laitinen
On 7/8/14, 7:14 AM

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/7/14, 9:15 AM
Seen: 3144 times
Last updated: 5/8/15, 1:21 AM