This question has been flagged
3 Replies
3710 Views

I added a new field in user called current_stock_owner.

My module will filter many views to show only stuff from the current stock owner of the logged user (a stock_owner is added in the relevant objects to match the current_stock_owner):

- Products

- Sales Orders

- Customers

- Etc.

How could I make a search filter to achieve that?

EDIT:

To be more explicit, stock_owner are our direct customers. They have their own products and sales order and their own customers list. When a user change its current_stock_owner, it will shown only relevant data by default.

Avatar
Discard
Best Answer

Hello ,

you can try like this for search view ,

<!-- search view -->

<record id="view_filter" model="ir.ui.view">

<field name="name">Product Details</field>

<field name="model">product.template</field>

<field name="type">search</field>

<field name="arch" type="xml">

<search string="Search By Product">

<group expand="0" string="Group By...">

<filter string="Product" domain="[]" context="{'group_by':'product'}"/>

 </group>

</search>

</field>

</record>

<!-- end code of search-->

Avatar
Discard
Author

It makes no sense... how could it work without any reference to my stock_owner and current_stock_owner fields?

Best Answer

I would try it the other way around. Make a field in Products, Sales Orders, etc, referring to the user who is the current stock owner. Then filter those objects (Products, etc) to only those items where the current logged user is the current stock owner. 

Avatar
Discard
Author

stock_owner isn't a user. It's a company like Mc Donald. Mc Donald has their own products, sales and customers they ship to. So when I select Mc Donald as my default_stock_owner in my user profile, I want to see only Mc Donald product, orders and customers by default, and filter out Burger King and Subway. Does it make sense?