This question has been flagged

Hello,

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,

Piotrek

Avatar
Discard
Author

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 :)

Best Answer

Piotrek,

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>

</xpath>

Hope it helps    

Avatar
Discard

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

Author

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