Odoo Help


Search filter based on a field from user object

Mathieu Laflamme
on 7/21/15, 9:41 AM 877 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?


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.

chirag jogi
On 7/24/15, 8:57 AM

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'}"/>





<!-- end code of search-->

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

Mathieu Laflamme
on 7/24/15, 10:29 AM
On 7/21/15, 10:01 AM

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. 

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?

Mathieu Laflamme
on 7/21/15, 12:59 PM

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/21/15, 9:41 AM
Seen: 877 times
Last updated: 7/24/15, 8:57 AM