diff --git a/bemade_sports_clinic/models/patient.py b/bemade_sports_clinic/models/patient.py index bafc132..123add1 100644 --- a/bemade_sports_clinic/models/patient.py +++ b/bemade_sports_clinic/models/patient.py @@ -310,6 +310,7 @@ class Patient(models.Model): followers, the set of followers should be the set of staff on all teams the patient is part of.""" for patient in self: + patient = patient.sudo() current_followers = patient.message_partner_ids future_followers = patient.team_ids.mapped("staff_ids").mapped("partner_id") removed_followers = current_followers - future_followers diff --git a/bemade_sports_clinic/models/res_users.py b/bemade_sports_clinic/models/res_users.py index 39fdf05..afecd60 100644 --- a/bemade_sports_clinic/models/res_users.py +++ b/bemade_sports_clinic/models/res_users.py @@ -40,7 +40,7 @@ class User(models.Model): [ { "team_id": team.id, - "partner_id": rec.id, + "partner_id": rec.partner_id.id, "role": "other", } for team in added_teams diff --git a/bemade_sports_clinic/tests/__init__.py b/bemade_sports_clinic/tests/__init__.py index 976c651..e5e9a1e 100644 --- a/bemade_sports_clinic/tests/__init__.py +++ b/bemade_sports_clinic/tests/__init__.py @@ -1,2 +1,3 @@ from . import test_patient from . import test_rights +from . import test_users diff --git a/bemade_sports_clinic/tests/test_rights.py b/bemade_sports_clinic/tests/test_rights.py index 13207c8..d27783b 100644 --- a/bemade_sports_clinic/tests/test_rights.py +++ b/bemade_sports_clinic/tests/test_rights.py @@ -23,7 +23,7 @@ class TestRights(TransactionCase): Command.set( cls.env.ref( "bemade_sports_clinic.group_sports_clinic_admin" - ).id, + ).ids, ), ], } @@ -38,14 +38,15 @@ class TestRights(TransactionCase): Command.set( cls.env.ref( "bemade_sports_clinic.group_sports_clinic_treatment_professional" - ).id, + ).ids, ), ], } ) - _logger.info( - f"Treatment Pro Groups: {cls.treatment_professional_user.groups_id.name}" - ) + # _logger.info( + # f"Treatment Pro Groups: " + # f"{cls.treatment_professional_user.groups_id.mapped('name')}" + # ) def test_treatment_pro_has_access_only_to_staffed_teams(self): """A treatment professional should only have access to teams and, diff --git a/bemade_sports_clinic/tests/test_users.py b/bemade_sports_clinic/tests/test_users.py new file mode 100644 index 0000000..3f57c50 --- /dev/null +++ b/bemade_sports_clinic/tests/test_users.py @@ -0,0 +1,35 @@ +from odoo.tests import TransactionCase, tagged, Form +from odoo import Command + + +@tagged("-at_install", "post_install") +class TestUsers(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def test_add_team_access_to_user(self): + user = self.env["res.users"].create( + { + "name": "test", + "login": "test", + "password": "test", + "groups_id": [ + Command.set( + self.env.ref( + "bemade_sports_clinic.group_sports_clinic_treatment_professional" + ).ids + ) + ], + } + ) + team = self.env["sports.team"].create( + { + "name": "Test", + } + ) + + self.assertNotIn(user, team.staff_ids.user_ids) + user.write({"accessible_team_ids": [Command.link(team.id)]}) + # user._inverse_accessible_team_ids() + self.assertIn(user, team.staff_ids.user_ids)