Skip to Content
Menu
This question has been flagged
6 Replies
3955 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

Avatar
Discard
Best Answer

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)

Thanks

Hope its helpful

Avatar
Discard
Best Answer

Hey @Zakaria,

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

Avatar
Discard
Author Best Answer

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 ?

Avatar
Discard

Hi Zak,

can you tell the exact criteria ?

Author

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

Best Answer

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')]]
Avatar
Discard