Add functionality to handle missing shifts in RotaBuilder and include worker grades in the timetable

This commit is contained in:
Ross
2026-01-07 22:14:43 +00:00
parent 277f14747a
commit 64c4189d5f
3 changed files with 205 additions and 151 deletions
+26 -1
View File
@@ -2439,13 +2439,37 @@ class RotaBuilder(object):
# nothing to constrain
continue
# Determine which of the requested shifts actually occur on the selected dates
present_shifts = set(
shift
for wk, d, shift in self.get_all_shiftname_combinations()
if (wk, d) in selected_weeks_days
)
requested_shifts = set(constraint_dict["shifts"])
used_shifts = requested_shifts.intersection(present_shifts)
missing_shifts = requested_shifts - present_shifts
if missing_shifts:
self.add_warning(
"avoid shifts by worker/dates",
(
f"Requested avoid shifts {sorted(list(missing_shifts))} for worker '{worker.name}'"
" are not present in the rota dates selected and will be ignored"
),
)
if not used_shifts:
# Nothing to constrain after filtering — skip adding the constraint
continue
# Add constraint that forbids the given shifts for this worker on the selected dates
self.model.constraints.add(
0
== sum(
self.model.works[worker.id, wk, d, shift]
for wk, d, shift in self.get_all_shiftname_combinations()
if (wk, d) in selected_weeks_days and shift in constraint_dict["shifts"]
if (wk, d) in selected_weeks_days and shift in used_shifts
)
)
@@ -5584,6 +5608,7 @@ class RotaBuilder(object):
worker_td = """<td title='Site: {site}' class='worker {site}'
data-worker-id='{worker_id}'
data-grade='{grade}'
data-nwds='{nwds}' data-site='{site}' data-worker='{name}'
data-fte='{fte}' data-fte_adj='{fte_adj}'
data-start_date='{start_date}'