a few more fixes and improvements

This commit is contained in:
Ross
2025-06-22 11:48:33 +01:00
parent 8402cc92fd
commit 82bc624a33
4 changed files with 153 additions and 49 deletions
+17
View File
@@ -1385,6 +1385,7 @@ class RotaBuilder(object):
)
# Most of our constraints apply per worker
# Worker constraint loop
worker: Worker
for worker in self.workers:
console.rule(
@@ -1392,6 +1393,22 @@ class RotaBuilder(object):
)
logging.debug(f"Generate worker constraints: {worker.name}")
if hasattr(worker, "max_shifts_per_week_by_shift_name"):
for shift_type, max_per_week in worker.max_shifts_per_week_by_shift_name.items():
if shift_type not in self.get_shift_names():
raise InvalidShift(
f"Worker '{worker.name}' has max_shifts_per_week_by_shift_name referencing non-existent shift: {shift_type}"
)
for week in self.weeks:
self.model.constraints.add(
sum(
self.model.works[worker.id, week, day, shift_type]
for day in days
if shift_type in self.get_shift_names_by_week_day(week, day)
) <= max_per_week
)
for week, day, shift in self.get_all_shiftclass_combinations():
# Only apply if this shift has force_assign_with set
if hasattr(shift, "force_assign_with") and shift.force_assign_with: