fix sudo issues around patient follower updating

This commit is contained in:
Marc Durepos 2024-09-18 14:38:34 -04:00
commit 1ab1d00cab
3 changed files with 8 additions and 25 deletions

View file

@ -132,7 +132,7 @@ class Patient(models.Model):
def write(self, values):
res = super().write(values)
if "team_ids" in values:
self.recompute_followers()
self.sudo().recompute_followers()
return res
@api.model_create_multi
@ -151,7 +151,7 @@ class Patient(models.Model):
.id
)
res = super().create(vals_list)
res.recompute_followers()
res.sudo().recompute_followers()
return res
@api.constrains("match_status", "practice_status")

View file

@ -103,28 +103,11 @@ class PatientInjury(models.Model):
else:
rec.stage = "active"
def write(self, vals):
super().write(vals)
if "treatment_professional_ids" in vals:
to_subscribe = self.treatment_professional_ids.mapped(
"partner_id"
) - self.message_follower_ids.mapped("partner_id")
self.message_subscribe(to_subscribe.ids)
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
for rec in res:
to_subscribe = rec.treatment_professional_ids.mapped(
"partner_id"
) - rec.message_follower_ids.mapped("partner_id")
_logger.debug(
f"Created injury {res.id}: {res.diagnosis}. Subscribing followers {to_subscribe}"
)
rec.message_subscribe(to_subscribe.ids)
_logger.debug(
f"Injury {res.id} now has followers {res.message_partner_ids}"
)
for rec in res.sudo():
rec.message_subscribe(rec.patient_id.message_partner_ids)
msg_body = _("A new injury was created for this patient.")
if rec.diagnosis:
msg_body += _(" Diagnosis: %s." % rec.diagnosis)

View file

@ -57,10 +57,10 @@ class SportsTeam(models.Model):
)
def write(self, vals):
previous_patient_ids = self.patient_ids
previous_patient_ids = self.sudo().patient_ids
res = super().write(vals)
if "staff_ids" in vals or "patient_ids" in vals:
(self.patient_ids | previous_patient_ids).recompute_followers()
(self.sudo().patient_ids | previous_patient_ids).recompute_followers()
return res
@api.model_create_multi
@ -68,8 +68,8 @@ class SportsTeam(models.Model):
res = super().create(vals_list)
for index, rec in enumerate(res):
if "staff_ids" in vals_list[index]:
rec._allow_access_for_staff_internal_users()
rec.patient_ids.recompute_followers()
rec.sudo()._allow_access_for_staff_internal_users()
rec.sudo().patient_ids.recompute_followers()
return res
def unlink(self):