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