Wednesday, March 22, 2017

Odoo 8 Many2many or One2many users field domain based on group

Here's an example of a collection of users that I wanted to be filtered by some group:

def _get_users_domain(self):
    return [('groups_id', 'in', self.env.ref('topo.users').id)]

user_ids = fields.Many2many('res.users', domain=_get_users_domain, string="Users", help="Who is allowed to access this board")

When you expose the field in a view, the selection widget should only show users that are members of the given group.

This should also work for a One2many field.