From d1fbbe2dc970e2e28ec592ec4f97a709ebf12241 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 9 Jul 2026 22:39:38 +0100 Subject: [PATCH] feat: add condition to check for week-day combinations before adding constraints in RotaBuilder --- rota_generator/shifts.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/rota_generator/shifts.py b/rota_generator/shifts.py index da5c53f..a479e2c 100644 --- a/rota_generator/shifts.py +++ b/rota_generator/shifts.py @@ -2788,18 +2788,19 @@ class RotaBuilder(object): "target_shifts": target_shifts, } - self.model.constraints.add( - inequality( - min_shifts, - sum( - self.model.works[worker.id, week, day, shift.name] - for week, day in self.get_week_day_combinations_for_shift( - shift - ) - ), - max_shifts, + if self.get_week_day_combinations_for_shift(shift): + self.model.constraints.add( + inequality( + min_shifts, + sum( + self.model.works[worker.id, week, day, shift.name] + for week, day in self.get_week_day_combinations_for_shift( + shift + ) + ), + max_shifts, + ) ) - ) else: # Make sure shifts aren't assigned to those from other sites # Not needed if there are no shifts