Odoo Help

Welcome!

This community 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.

0

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

By
Miku Laitinen
on 7/7/14, 9:15 AM 1,981 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.

1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
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.

0

René Schuster

--René Schuster--
1560
| 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.

Regards.

0
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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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