From 8b210839f8d1a3c092b6c90972eea7fd1f235e80 Mon Sep 17 00:00:00 2001 From: FernandoRomera Date: Sat, 14 Mar 2026 07:39:06 +0100 Subject: [PATCH] [18.0][IMP] hr_shift: resilience --- hr_shift/models/shift_planning.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hr_shift/models/shift_planning.py b/hr_shift/models/shift_planning.py index c0cbdc5..97e70ea 100644 --- a/hr_shift/models/shift_planning.py +++ b/hr_shift/models/shift_planning.py @@ -409,10 +409,12 @@ def _compute_display_name(self): line.display_name = ( f"{_(dict(WEEK_DAYS_SELECTION).get(line.day_number))} - " f""" - {line.template_id.name - or dict( - self._fields['state']._description_selection(self.env) - )[line.state]}""" + { + line.template_id.name + or dict(self._fields["state"]._description_selection(self.env))[ + line.state + ] + }""" ) @api.depends("planning_id", "day_number", "template_id") @@ -428,7 +430,7 @@ def _compute_shift_time(self): and shift.template_id._prepare_time()["end_time"] or {"hour": 23, "minute": 59} ) - tz = pytz.timezone(shift.template_id.tz or self.env.user.tz) + tz = pytz.timezone(shift.template_id.tz or self.env.user.tz or "UTC") start_time = tz.localize( datetime.combine( shift_date, @@ -450,7 +452,7 @@ def _compute_shift_time(self): def _compute_start_date(self): for shift in self: - local_tz = pytz.timezone(shift.template_id.tz or self.env.user.tz) + local_tz = pytz.timezone(shift.template_id.tz or self.env.user.tz or "UTC") shift.start_date = ( pytz.utc.localize(shift.start_time) .astimezone(local_tz) @@ -475,7 +477,7 @@ def _is_public_holiday(self): def _is_on_leave(self): if not (self.start_time and self.end_time and self.employee_id): return False - local_tz = pytz.timezone(self.template_id.tz or self.env.user.tz) + local_tz = pytz.timezone(self.template_id.tz or self.env.user.tz or "UTC") start_time = fields.datetime.combine( pytz.utc.localize(self.start_time).astimezone(local_tz), self.start_time.min.time(),