a few more fixes and improvements
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user