Add rota-builder summary to detail view with weeks, shifts, and workers count
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user