Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4113 Vizualizări
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?

Imagine profil
Abandonează
Cel mai bun răspuns

Hello FarFarAway,

You can try on change method for many2many domain.

team = fields.Many2one("maintenance.team", "Team")

@api.onchange('team')
def onchange_team_id(self):
return {'domain': {
'work_shift_lines_ids': [('user_id', 'in', self.team.member_ids.ids)]
}}

work_shift_lines_ids = fields.Many2many("hr.employee", relation="shift_one_relation")

Hope this may help you!


Thanks & Regards,

Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

Imagine profil
Abandonează
Autor

That works, thank you.

Related Posts Răspunsuri Vizualizări Activitate
0
nov. 22
80
1
iun. 22
7093
1
iul. 21
2707
9
feb. 16
49130
1
oct. 15
10674