Odoo Help


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.


Domain for sale.order.line to show only products that belongs to selected company_id

Piotr Piotrowski
on 9/22/15, 5:36 AM 996 views


I just lost my hope, that I will solve this problem alone and I cannot find any solution or even suggestion how to do this.

So the problem:

I have multicompany env with 3 companys:

COM_1, COM_2, COM_3

Every company has it`s own products. When I create SALE.ORDER and I add SALE.ORDER.LINE I can select ALL products that belongs to companys, to which my current RES.USER has access. But this cause later a lot of problems, so I would like to limit selection list to products, that belongs to company selected on SALE.ORDER form.

I hope this is more or less understandable ;)

So what I would like to achieve is:

- on sale.order form I select company, let`s say COM_1

- on sale.order.line I add products and I see ONLY products that belongs to COM_1

Could someone please help me with this task?

Thanks in advance,


Pawan, sorry for answering here, but my karma... well You are right! Actually I`ve tried this or something similar before, but somehow it does not worked. Maybe I wrote domain incorrectly, anyway working solution is below: <xpath expr="//tree[@string='Sales Order Lines']/field[@name='product_id']" position="attributes"> [('company_id', '=', parent.company_id)] Thanks for help :)

Piotr Piotrowski
on 9/22/15, 9:14 AM


| 4 3 5
Hyderabad, India

On 9/22/15, 7:32 AM


You achieve acheive this simply by adding domain to your product field in sale.order.line object both its tree and form view for Sale order (by overriding the form view of sale.order)

and at product_id field do this

<xpath expr="//YOUR_PATH_TO_product_id" position="attributes">
<attribute name="domain">[('company_id', '=', parent.company_id.id)]</attribute>


Hope it helps    

IIRC in v7 company_id is a related field in sale.order, based on the shop_id. This causes problems filtering before you've saved the order for the first time. You'll need to update onchange_shop_id() to update company_id on sale.order prior to saving. This allows proper filtering using the domain you listed. (This behavior may have changed in v8.)

Brett Lehrer
on 9/22/15, 9:05 AM

Thanks, it is working :) <xpath expr="//tree[@string='Sales Order Lines']/field[@name='product_id']" position="attributes"> [('company_id', '=', parent.company_id)]

Piotr Piotrowski
on 9/22/15, 9:14 AM

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

2 follower(s)


Asked: 9/22/15, 5:36 AM
Seen: 996 times
Last updated: 3/13/16, 5:18 AM