From e029464fa283090356bb23180e5a5be886c69dbf Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 7 Sep 2022 19:02:24 +0300 Subject: [PATCH] Update calculating rotation index for updated shift, fix schedule preview with respect to rotation index --- engine/apps/schedules/models/custom_on_call_shift.py | 6 +++++- engine/apps/schedules/models/on_call_schedule.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/apps/schedules/models/custom_on_call_shift.py b/engine/apps/schedules/models/custom_on_call_shift.py index 67474225..64077f4f 100644 --- a/engine/apps/schedules/models/custom_on_call_shift.py +++ b/engine/apps/schedules/models/custom_on_call_shift.py @@ -561,7 +561,11 @@ class CustomOnCallShift(models.Model): instance_data["rotation_start"].date(), instance_data["start"].time(), ).astimezone(pytz.UTC) - instance_data["start_rotation_from_user_index"] = self.get_rotation_user_index() + # calculate rotation index to keep user rotation order + start_rotation_from_user_index = self.get_rotation_user_index() + self.start_rotation_from_user_index + if start_rotation_from_user_index >= len(instance_data["rolling_users"]): + start_rotation_from_user_index = 0 + instance_data["start_rotation_from_user_index"] = start_rotation_from_user_index if self.last_updated_shift is None or self.last_updated_shift.event_is_started: # create new shift diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index d6abefd1..08596c2d 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -676,6 +676,7 @@ class OnCallScheduleWeb(OnCallSchedule): pass else: if update_shift.event_is_started: + custom_shift.start_rotation_from_user_index = update_shift.start_rotation_from_user_index update_shift.until = custom_shift.rotation_start extra_shifts.append(update_shift) else: