from odoo import api, fields, models class InternalTeams(models.Model): _name = "internal.teams" team_name = fields.Text("Team Name", required=True) team_lead = fields.Many2one("res.users", string="Team Lead") members_ids = fields.Many2many('res.users', 'internal_team_user_rel', 'team_id', 'user_id', 'Team Members', help="""Team Members are the users who are working in this particular team.""" ) active = fields.Boolean(default=True, help="Set active to false to hide the Teams without removing it.") parent_id = fields.Many2one('internal.teams', string="Parent Team", domain="[('id', '!=', id)]") child_ids = fields.One2many('internal.teams', 'parent_id', string="Child Teams") active = fields.Boolean(default=True) # Computed field to include members + child team members and leads all_members_ids = fields.Many2many( 'res.users', compute='_compute_all_members', string="All Members", store=False ) @api.depends('members_ids', 'child_ids.members_ids', 'child_ids.team_lead') def _compute_all_members(self): for rec in self: all_members = rec.members_ids for child in rec.child_ids: all_members |= child.members_ids | child.team_lead rec.all_members_ids = all_members def _compute_display_name(self): """ Custom display_name in case a registration is nott linked to an attendee """ for registration in self: registration.display_name = registration.team_name