Odoo Help


How to filter the list of users in Many2one filed ?

on 6/19/17, 8:34 AM 283 views

Hello my friends,

I have defined a field in my class which show me the list of users in the database:

But i want to show only a certain type of users where the connected user have type "A", and certain type of users where the conncted user have type "B".

Can i filer a field using rule ? how i can realize that ? Thank you for help

On 2/25/18, 11:48 PM

You can use default method on many2one fields.

def default_users(self):
     if self.env.user.type == 'Admin':
         return manager_users
     elif self.env.user.type == 'Manager':
         return worker_user 
 users = fields.Many2one('users.model','Users',default=default_users)


Hope its helpful

Dipak Shah
On 1/12/18, 1:26 AM

Hey @Zakaria,

Please use name_search method where you can check your connected user (logged in) and also filter the results (users) accordingly.

On 6/19/17, 10:31 AM

Thank you @EmanuelCino. My question was as follows:

If a connected user is a "manager" he should see only "workers" in the user field (the list of users)

And if the user is "Admin" he will should see only " managers in the user field.

How i can filer the user_id field so ?

Hi Zak,

can you tell the exact criteria ?

Niyas Raphy
on 6/19/17, 11:04 AM

Hi Niyas i want to filter my many2one field;

I have this field which allows me to display and choose the users ( to assign each object to each user ) : approved_by = fields.Many2one('res.users', 'Affecter à')

And i have 3 users groups : Admin and manager and worker

When the manager connect he should see only users in the user field

And when the Admin connect he should see only manager in the user field

on 6/19/17, 11:13 AM
Emanuel Cino
On 6/19/17, 10:05 AM

Here should be your field definition :

user_id = fields.Many2one('res.users', 'User', domain=['|', ('type', '=', 'A'), '&', ('type', '=', 'B'), ('criteria_to_show_type_b', '=', 'value_of criteria')]]

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: 6/19/17, 8:34 AM
Seen: 283 times
Last updated: 2/25/18, 11:48 PM