class Example(models.Model):
_name = "example.model"
team = fields.Many2one("maintenance.team", "Team")
@api.depends("team")
def _team_member_ids(self):
print(self.team.member_ids.ids) # this correctly prints user IDs for users set in that team
# below domain however returns nothing
return [('user_id', 'in', self.team.member_ids.ids)]
work_shift_lines_ids = fields.Many2many("hr.employee", relation="shift_one_relation", domain=_team_member_ids)
I would expect this to work but my field work_shift_lines_ids does not offer anything when I select it.
I expect it to filter only those employees that have user_id in team.member_ids
I checked both models, this is how built in maintenance.team model defines member_ids:
class MaintenanceTeam(models.Model):
_name = 'maintenance.team'
# some other fields...
member_ids = fields.Many2many(
'res.users', 'maintenance_team_users_rel', string="Team Members",
domain="[('company_ids', 'in', company_id)]")
As you can see member_ids is just Many2many to res.users so when I did self.team.member_ids.ids it will just give me list like [2, 24] (this works I tested).
For the first part of domain, where I did 'user_id' , my logic is since work_shift_lines_ids is defined as Many2many hr.employee model and hr.employee has user_id field it will take that field and run it trough self.team.member_ids.ids.
I also tried
[('user_id.id', 'in', self.team.member_ids.ids)]
but again nothing is showing in selection.
I also declared my domain with @api.depends("team") as I would like it to get updated when team changes, not sure if this works since I can't test because my domain is broken but is this logic correct?