diff --git a/bemade_sports_clinic/__manifest__.py b/bemade_sports_clinic/__manifest__.py index 42eb42b..4a66b75 100644 --- a/bemade_sports_clinic/__manifest__.py +++ b/bemade_sports_clinic/__manifest__.py @@ -17,10 +17,10 @@ # DEALINGS IN THE SOFTWARE. # { - 'name': 'Sports Clinic Management', - 'version': '16.0.1.5.10', - 'summary': 'Manage the patients of a sports medicine clinic.', - 'description': """ + "name": "Sports Clinic Management", + "version": "16.0.1.6.0", + "summary": "Manage the patients of a sports medicine clinic.", + "description": """ Adds the notion of sports teams, players (patients), coaches and treatment professionals. The core purpose of this module is to keep track of the treatment history of players and to make it appropriately accessible to the various @@ -33,26 +33,26 @@ External users (portal users) can be added to give coaches and other team personnel access to limited player data such as estimated return-to-play dates. """, - 'category': 'Services/Medical', - 'author': 'Bemade Inc.', - 'website': 'https://www.bemade.org', - 'license': 'OPL-1', - 'depends': ['portal', 'contacts'], - 'data': [ - 'security/sports_clinic_groups.xml', - 'security/ir.model.access.csv', - 'security/sports_clinic_rules.xml', - 'data/sports_clinic_data.xml', - 'views/sports_team_views.xml', - 'views/sports_clinic_menus.xml', - 'views/sports_patient_injury_views.xml', - 'views/sports_patient_views.xml', - 'views/sports_clinic_portal_views.xml', - 'views/res_partner_views.xml', - 'views/res_users_views.xml', + "category": "Services/Medical", + "author": "Bemade Inc.", + "website": "https://www.bemade.org", + "license": "OPL-1", + "depends": ["portal", "contacts"], + "data": [ + "security/sports_clinic_groups.xml", + "security/ir.model.access.csv", + "security/sports_clinic_rules.xml", + "data/sports_clinic_data.xml", + "views/sports_team_views.xml", + "views/sports_clinic_menus.xml", + "views/sports_patient_injury_views.xml", + "views/sports_patient_views.xml", + "views/sports_clinic_portal_views.xml", + "views/res_partner_views.xml", + "views/res_users_views.xml", ], - 'demo': ['data/demo/sports_clinic_demo_data.xml'], - 'installable': True, - 'auto_install': False, - 'application': True, + "demo": ["data/demo/sports_clinic_demo_data.xml"], + "installable": True, + "auto_install": False, + "application": True, } diff --git a/bemade_sports_clinic/migrations/16.0.1.6.0/post-migrate.py b/bemade_sports_clinic/migrations/16.0.1.6.0/post-migrate.py new file mode 100644 index 0000000..29f6e35 --- /dev/null +++ b/bemade_sports_clinic/migrations/16.0.1.6.0/post-migrate.py @@ -0,0 +1,6 @@ +from odoo import api, SUPERUSER_ID + + +def migrate(cr, version): + env = api.Environment(cr, SUPERUSER_ID, {}) + env["sports.patient"].search([]).recompute_followers() diff --git a/bemade_sports_clinic/models/patient_injury.py b/bemade_sports_clinic/models/patient_injury.py index 712833a..6ecf50d 100644 --- a/bemade_sports_clinic/models/patient_injury.py +++ b/bemade_sports_clinic/models/patient_injury.py @@ -35,7 +35,11 @@ class PatientInjury(models.Model): # TODO: Add field consentement_parental = fields.Selection(oui, non, non-applicable) patient_id = fields.Many2one( - comodel_name="sports.patient", string="Patient", readonly=True, required=True + comodel_name="sports.patient", + string="Patient", + readonly=True, + required=True, + ondelete="cascade", ) patient_name = fields.Char(related="patient_id.name") diagnosis = fields.Char(tracking=True) diff --git a/bemade_sports_clinic/tests/test_patient.py b/bemade_sports_clinic/tests/test_patient.py index 67cbc41..8d012cb 100644 --- a/bemade_sports_clinic/tests/test_patient.py +++ b/bemade_sports_clinic/tests/test_patient.py @@ -143,15 +143,39 @@ class TestPatient(TransactionCase): self.assertIn(cp_id, injury.message_partner_ids) def test_removing_second_team_correctly_adjusts_staff(self): + """Tests both removing from the team side and from the patient side.""" team2, therapist, coach = self._generate_second_team_and_staff() self.patient1.write({"team_ids": [Command.link(team2.id)]}) self.assertIn(self.patient1, team2.patient_ids) self.assertIn(therapist, self.patient1.message_partner_ids) + team2.write({"patient_ids": [Command.unlink(self.patient1.id)]}) + self.assertNotIn(self.patient1, team2.patient_ids) self.assertEqual(self.patient1.message_partner_ids, coach) self.assertEqual(self.patient1_injury.message_partner_ids, coach) + self.patient1.write({"team_ids": [Command.link(team2.id)]}) + + self.assertIn(self.patient1, team2.patient_ids) + self.assertIn(therapist, self.patient1.message_partner_ids) + + self.patient1.write({"team_ids": [Command.unlink(team2.id)]}) + + self.assertNotIn(self.patient1, team2.patient_ids) + self.assertEqual(self.patient1.message_partner_ids, coach) + self.assertEqual(self.patient1_injury.message_partner_ids, coach) + + def test_adding_patient_injury_sets_followers(self): + injury2 = self.env["sports.patient.injury"].create( + { + "patient_id": self.patient1.id, + "diagnosis": "some other injury", + } + ) + + self.assertEqual(injury2.message_partner_ids, self.coach.partner_id) + def _generate_second_team_and_staff(self): team2 = self.env["sports.team"].create( {