Skip to content

feat: editable calendar with rule-checked edits, undo and PDF export - #6

Merged
kris7011 merged 4 commits into
mainfrom
feature/editable-calendar-undo-pdf
Nov 1, 2026
Merged

kris7011 merged 4 commits into
mainfrom
feature/editable-calendar-undo-pdf

Conversation

@kris7011

@kris7011 kris7011 commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Purpose

Let a planner correct a generated schedule by hand without breaking the rules the scheduler follows, undo mistakes, and hand out the result as a PDF. Calendar view and PDF export were listed as planned features.

Implementation

  • app/schedule_editor.py (no Tk): add, remove and replace employees on a shift. Validation reuses Employee.get_shift_blockers (skill, capacity, one shift per day, rest time) plus "already assigned" and "fully staffed". A refused change raises ScheduleEditError with all reasons and changes nothing. A replacement is checked as if the current employee had left.
  • Undo: the command pattern. Each edit stores the list positions it touched; undo restores the exact earlier state, including order.
  • app/calendar_view.py: "Kalender" tab with a dates × Dag/Aften/Nat grid and staffing colours. The edit panel lists every employee, with Danish reasons for those who cannot take the shift. A change history sits under the calendar; undo is available as a button and Ctrl+Z. The other tabs refresh after each change.
  • app/pdf_export.py (ReportLab, BSD): period, print time, number of manual changes, all shifts (missing staff highlighted) and an employee workload table. It refuses to overwrite unless allowed (the GUI allows it only after the save dialog's confirmoverwrite), and writes atomically via a temp file and os.replace.
  • Data safety: edits stay in memory, and the CSV inputs are never written. "Kør vagtplan" asks before discarding manual changes.
  • New runtime dependency: reportlab>=5.1,<6 (requirements.txt).

Testing

  • python -m pytest: 72 passed (24 new: 19 editor, 5 PDF). The tests don't import Tkinter.
  • Desktop demo on Windows 11 / Python 3.12 / Tk 8.6: the real window was driven via the real buttons' invoke(); only the modal dialogs were stubbed.
    • A rule violation was refused with both reasons.
    • Replace + add staffed the open shift (unassigned 1 → 0).
    • The PDF was exported: "12 fuldt bemandede … Manuelle ændringer: 2".
    • Undo restored the previous state (unassigned back to 1).
    • The CSV hashes were unchanged.
    • Screenshots are in docs/images/.
  • The demo found two layout bugs in the first version (the edit panel could be pushed out of the window; the history was clipped). Both are fixed here.

Not covered

  • Tk widgets have no automated tests (they contain no rules).
  • There is no redo, and no saving of an edited schedule.
  • See docs/PROJECT_WALKTHROUGH.md.

🤖 Generated with Claude Code

kris7011 and others added 4 commits November 1, 2026 10:27
Add ScheduleEditor for adding, removing and replacing employees on a
generated schedule. Every change is checked with Employee's own
scheduler rules (skill, capacity, one shift per day, rest time) plus
"already assigned" and "fully staffed"; a refused change raises
ScheduleEditError with all reasons and leaves the schedule unchanged.
Edits are recorded as commands with list positions, so undo restores
the exact previous state. Also adds calendar grouping and Danish rule
descriptions for the GUI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Export the schedule with ReportLab: period, print time, number of
manual changes, all shifts (missing staff highlighted) and employee
workload. An existing file is only replaced when the caller allows it,
and the PDF is written to a temporary file and moved into place, so a
failed export never damages an existing file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a "Kalender" tab (dates x day/evening/night) where a shift can be
selected and employees added, removed or replaced through the
ScheduleEditor. Candidates show why they cannot take a shift, refused
changes show every reason, and all tabs refresh after a change. Undo is
available as a button and Ctrl+Z with a change history. "Eksportér
PDF" uses the save dialog's overwrite confirmation. Regenerating the
plan asks first when there are manual changes; the CSV files are never
written. The default window is slightly larger so a week fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kris7011
kris7011 merged commit ad20bd3 into main Nov 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant