From c135c3eef7f356d11f3e9ca87503b9fd0f16825e Mon Sep 17 00:00:00 2001 From: Denis Durepos Date: Sun, 10 Aug 2025 05:47:16 -0400 Subject: [PATCH] Fixed injured player count issue to reflect v16.0 logic of basing injured count on player stage rather than active injuries. --- bemade_sports_clinic/models/patient.py | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/bemade_sports_clinic/models/patient.py b/bemade_sports_clinic/models/patient.py index 5154aeb..5f92ef2 100644 --- a/bemade_sports_clinic/models/patient.py +++ b/bemade_sports_clinic/models/patient.py @@ -254,18 +254,24 @@ class Patient(models.Model): @api.depends("practice_status", "match_status", "injury_ids.injury_date") def _compute_is_injured(self): for patient in self: - active_injuries = self.env["sports.patient.injury"].search( - [ - ("patient_id", "=", patient.id), - ("stage", "=", "active"), - ] - ) - if active_injuries: - patient.is_injured = True - injury_dates = [d for d in active_injuries.mapped("injury_date") if d] - patient.injured_since = min(injury_dates) if injury_dates else False + # Patient is injured if their stage is not "healthy" + patient.is_injured = patient.stage != "healthy" + + # For injured_since, find the earliest injury date from active injuries + # This logic is kept but may not be reliable until user habits change + if patient.is_injured: + active_injuries = self.env["sports.patient.injury"].search( + [ + ("patient_id", "=", patient.id), + ("stage", "=", "active"), + ] + ) + if active_injuries: + injury_dates = [d for d in active_injuries.mapped("injury_date") if d] + patient.injured_since = min(injury_dates) if injury_dates else False + else: + patient.injured_since = False else: - patient.is_injured = False patient.injured_since = False def _compute_treatment_note_count(self):