Skip to Content
Menu
This question has been flagged
1 Reply
1883 Views

Hi, 

Need your assistance please.

I have a form where I need to select from a many2one field a user from a certain group, sales group only. Odoo 13

I`ve searched and I`m a newbie in understanding the code a little bit.

Thank you

Avatar
Discard
Best Answer

Hi,

Try the below code.

class YourModel(models.Model):
_name = 'your.model'
def _get_many2one_field(self):
users_search = self.env['res.users'].search([])
users = []
for user in users_search:
if user.has_group('your_group'):
users.append(user.id)
return [('id', 'in', users)]
many2one_field = fields.Many2one('res.users',domain=_get_many2one_field)
Here I have given a domain for the many2one_field,that function will check the users is in a particular group using has_group method.

Regards


Avatar
Discard