Add rota-builder summary to detail view with weeks, shifts, and workers count

This commit is contained in:
Ross
2025-12-17 17:25:22 +00:00
parent 8458279e19
commit 023e345591
4 changed files with 140 additions and 3 deletions
+22 -2
View File
@@ -55,14 +55,34 @@ class RotaSchedule(models.Model):
)
# compute weeks_to_rota (integer number of weeks)
delta = self.end_date - self.start_date
weeks_to_rota = max(1, int(delta.days // 7))
# Prefer an explicit value stored in `self.options['weeks']` (set by
# the rota edit form). If absent, fall back to deriving from the
# stored end_date (backwards compatible).
opts_preview = dict(self.options or {})
weeks_opt = None
if "weeks" in opts_preview:
try:
weeks_opt = int(opts_preview.get("weeks"))
except Exception:
weeks_opt = None
if weeks_opt is not None:
weeks_to_rota = max(1, weeks_opt)
else:
delta = self.end_date - self.start_date
weeks_to_rota = max(1, int(delta.days // 7))
# Build kwargs for RotaBuilder from any explicit builder args stored in
# `self.options` (kept for backward compatibility), and treat the
# remaining keys as constraint options which should map to
# `RotaConstraintOptions`.
opts = dict(self.options or {})
# Remove 'weeks' from opts before handing to constraint options so
# it doesn't cause validation failures in RotaConstraintOptions.
if "weeks" in opts:
try:
opts.pop("weeks")
except Exception:
pass
builder_keys = [
"balance_offset_modifier",
"ltft_balance_offset",