From b72d33189c7214790fd5eefe3e06862f99571a8f Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 11 Aug 2025 13:56:43 +0100 Subject: [PATCH] Add ignore_shifts parameter to PostShiftConstraint and PreShiftConstraint --- gen_cons.py | 2 +- rota/shifts.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gen_cons.py b/gen_cons.py index 997afa1..41366e6 100644 --- a/gen_cons.py +++ b/gen_cons.py @@ -353,7 +353,7 @@ def main( #{"name": "pre", "options": 2}, #{"name": "post", "options": 1}, - PostShiftConstraint(days=1, start_date="2025-11-24"), + PostShiftConstraint(days=1, start_date="2025-11-17", ignore_shifts=["oncall"]), ], display_char="a", #force_assign_with=["oncall"] diff --git a/rota/shifts.py b/rota/shifts.py index 00d36c6..8930e31 100644 --- a/rota/shifts.py +++ b/rota/shifts.py @@ -96,9 +96,11 @@ class NightConstraint(BaseShiftConstraint): class PreShiftConstraint(BaseShiftConstraint): days: Any = None + ignore_shifts: List[str] = [] class PostShiftConstraint(BaseShiftConstraint): days: Any = None + ignore_shifts: List[str] = [] class BalanceAcrossGroupsConstraint(BaseShiftConstraint): """""" @@ -2898,6 +2900,7 @@ class RotaBuilder(object): PreShiftConstraint ): constraint = constraint_shift.get_constraint(PreShiftConstraint) + ignore_shifts = constraint.ignore_shifts + [constraint_shift.name] if week not in constraint.weeks: continue for n in range(0, constraint.days): @@ -2922,7 +2925,7 @@ class RotaBuilder(object): for shiftname in self.get_shift_names_by_week_day( pre_map[n][1], pre_map[n][2] ) - if shiftname != constraint_shift.name + if shiftname not in ignore_shifts for w in workers if w.site in constraint_shift.sites # Only workers who can work this shift ) @@ -2932,6 +2935,7 @@ class RotaBuilder(object): PostShiftConstraint ): constraint = constraint_shift.get_constraint(PostShiftConstraint) + ignore_shifts = constraint.ignore_shifts + [constraint_shift.name] if week not in constraint.weeks: continue for n in range(0, constraint.days): @@ -2956,7 +2960,7 @@ class RotaBuilder(object): for shiftname in self.get_shift_names_by_week_day( post_map[n][1], post_map[n][2] ) - if shiftname != constraint_shift.name + if shiftname not in ignore_shifts for w in workers if w.site in constraint_shift.sites # Only workers who can work this shift )