Complete NextSteps roadmap: planning engine UI, calendar cluster, flexible wishes
Works through every numbered item in NextSteps260913.md section 3, plus the three known verification issues in section 4.1. Surface what the backend already computed: - 3.1 render surplus_advice in PlanResults, mirroring the shortfall remedies - 3.2 surface VacationBalance.is_assumed so assumed statutory years are visible - 3.3 age-4 expiry given the proposed plan, via a new Age4Projection reusing the existing _age4_projections arithmetic (Dashboard stat verified, not rebuilt) Calendar cluster (one pass over the holiday data): - new GET /api/calendar/days exposing roda dagar, klamdagar and day overrides, paginated four years at a time - 3.4 shade roda dagar/klamdagar, with R/K badges so colour is not the only signal - 3.6 click-to-override behind an explicit mode toggle, leaving drag multi-select intact - 3.7 click month/year to advance - 3.8 per-year red-days list in Settings, statutory days plus overrides i18n: - 3.5 five backend-generated Swedish surfaces converted to message_key + data, following the tips_service pattern; old string fields replaced, not kept Flexible wishes (3.9): - PLANNING_ENGINE_SPEC section 10: window_mode, candidate search, cost function, deterministic tie-break, two-pass ordering, test matrix rows 15-24 - backend: entity, migration 006, _FULL_SCHEMA sync, repository, allocator - frontend: season-preset toggle in WishEditor, unplaced outcome rendering Fixes (4.1): - pin typecheck to the local tsc rather than npx resolving a newer TypeScript - ignore generated coverage/ and dist/ in the ESLint flat config - fix the flaky usePlanApply test properly, with waitFor rather than a retry Tests: backend 361 -> 404, frontend 540 -> 704. Coverage 89.47% -> 96.52% lines. Not yet verified in a browser. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Add workspace.planning_mode and child.preschool_planning_days_per_year.
|
||||
|
||||
Revision ID: 002
|
||||
Revises: 001
|
||||
Create Date: 2026-09-12
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "002"
|
||||
down_revision: str | None = "001"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
_UPGRADE_SQL = """
|
||||
ALTER TABLE workspace ADD COLUMN planning_mode TEXT NOT NULL DEFAULT 'solo'
|
||||
CHECK (planning_mode IN ('solo','couple'));
|
||||
|
||||
ALTER TABLE child ADD COLUMN preschool_planning_days_per_year INTEGER NOT NULL DEFAULT 6
|
||||
CHECK (preschool_planning_days_per_year >= 0 AND preschool_planning_days_per_year <= 30);
|
||||
"""
|
||||
|
||||
_DOWNGRADE_SQL = """
|
||||
ALTER TABLE child DROP COLUMN preschool_planning_days_per_year;
|
||||
ALTER TABLE workspace DROP COLUMN planning_mode;
|
||||
"""
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _UPGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _DOWNGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
@@ -0,0 +1,134 @@
|
||||
"""Rename break_period -> leave_wish and add recurrence/priority/parent fields.
|
||||
|
||||
`break_period` modeled "N weeks home together in this window" — single-year,
|
||||
no recurrence, no priority, no notion of which parent. The planning engine
|
||||
(PLANNING_ENGINE_SPEC.md §2.1) needs all three, so the table is renamed and
|
||||
extended rather than adding a parallel concept. Safe to do now: the table has
|
||||
zero rows in production.
|
||||
|
||||
The recurring window is stored as month/day integers (not dates) so it can
|
||||
repeat yearly without a custom SQLite type; old `start_date`/`end_date` rows
|
||||
are backfilled into `window_*` columns and the date columns are then dropped.
|
||||
|
||||
Revision ID: 003
|
||||
Revises: 002
|
||||
Create Date: 2026-09-12
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "003"
|
||||
down_revision: str | None = "002"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
_UPGRADE_SQL = """
|
||||
ALTER TABLE break_period RENAME TO leave_wish;
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN child_id TEXT
|
||||
REFERENCES child(id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN window_start_month INTEGER NOT NULL DEFAULT 1
|
||||
CHECK (window_start_month >= 1 AND window_start_month <= 12);
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN window_start_day INTEGER NOT NULL DEFAULT 1
|
||||
CHECK (window_start_day >= 1 AND window_start_day <= 31);
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN window_end_month INTEGER NOT NULL DEFAULT 1
|
||||
CHECK (window_end_month >= 1 AND window_end_month <= 12);
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN window_end_day INTEGER NOT NULL DEFAULT 1
|
||||
CHECK (window_end_day >= 1 AND window_end_day <= 31);
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN recurrence TEXT NOT NULL DEFAULT 'once'
|
||||
CHECK (recurrence IN ('yearly','once'));
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN first_year INTEGER NOT NULL DEFAULT 2026;
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN last_year INTEGER;
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN priority INTEGER NOT NULL DEFAULT 1
|
||||
CHECK (priority >= 1);
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN parent_mode TEXT NOT NULL DEFAULT 'either'
|
||||
CHECK (parent_mode IN ('either','both','specific'));
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN parent_personal_data_uuid TEXT
|
||||
REFERENCES personal_data(uuid) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN goal_override TEXT
|
||||
CHECK (goal_override IS NULL OR goal_override IN ('max_time','max_money','balanced'));
|
||||
|
||||
UPDATE leave_wish SET
|
||||
recurrence = 'once',
|
||||
priority = 1,
|
||||
parent_mode = 'either',
|
||||
first_year = CAST(strftime('%Y', start_date) AS INTEGER),
|
||||
last_year = CAST(strftime('%Y', start_date) AS INTEGER),
|
||||
window_start_month = CAST(strftime('%m', start_date) AS INTEGER),
|
||||
window_start_day = CAST(strftime('%d', start_date) AS INTEGER),
|
||||
window_end_month = CAST(strftime('%m', end_date) AS INTEGER),
|
||||
window_end_day = CAST(strftime('%d', end_date) AS INTEGER);
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN start_date;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN end_date;
|
||||
"""
|
||||
|
||||
_DOWNGRADE_SQL = """
|
||||
ALTER TABLE leave_wish ADD COLUMN start_date DATE;
|
||||
|
||||
ALTER TABLE leave_wish ADD COLUMN end_date DATE;
|
||||
|
||||
UPDATE leave_wish SET
|
||||
start_date = printf('%04d-%02d-%02d', first_year, window_start_month, window_start_day),
|
||||
end_date = printf(
|
||||
'%04d-%02d-%02d',
|
||||
CASE WHEN (window_end_month, window_end_day) < (window_start_month, window_start_day)
|
||||
THEN first_year + 1 ELSE first_year END,
|
||||
window_end_month,
|
||||
window_end_day
|
||||
);
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN goal_override;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN parent_personal_data_uuid;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN parent_mode;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN priority;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN last_year;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN first_year;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN recurrence;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN window_end_day;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN window_end_month;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN window_start_day;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN window_start_month;
|
||||
|
||||
ALTER TABLE leave_wish DROP COLUMN child_id;
|
||||
|
||||
ALTER TABLE leave_wish RENAME TO break_period;
|
||||
"""
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _UPGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _DOWNGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Add day_override table.
|
||||
|
||||
Lets a workspace correct the calendar cache (`app/data/swedish_calendar.json`)
|
||||
in either direction on a per-date basis: `is_working_day=false` means the
|
||||
workspace is off that day even though the calendar calls it a working day
|
||||
(e.g. a klämdag their employer gives off); `is_working_day=true` means the
|
||||
workspace must work despite the calendar (e.g. julafton is a normal workday
|
||||
there). See PLANNING_ENGINE task notes / app.services.allocation_service.
|
||||
|
||||
Revision ID: 004
|
||||
Revises: 003
|
||||
Create Date: 2026-09-13
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "004"
|
||||
down_revision: str | None = "003"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
_UPGRADE_SQL = """
|
||||
CREATE TABLE IF NOT EXISTS day_override (
|
||||
id TEXT PRIMARY KEY,
|
||||
workspace_id TEXT NOT NULL,
|
||||
date DATE NOT NULL,
|
||||
is_working_day INTEGER NOT NULL,
|
||||
note TEXT,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
UNIQUE(workspace_id, date),
|
||||
FOREIGN KEY (workspace_id) REFERENCES workspace(id) ON DELETE CASCADE
|
||||
);
|
||||
"""
|
||||
|
||||
_DOWNGRADE_SQL = """
|
||||
DROP TABLE IF EXISTS day_override;
|
||||
"""
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _UPGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _DOWNGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
@@ -0,0 +1,44 @@
|
||||
"""Add personal_data.min_vacation_days_per_year.
|
||||
|
||||
Semesterlagen requires a minimum number of vacation days to be *taken* each
|
||||
year (statutory 20); only days above that minimum may be saved, for up to 5
|
||||
years. Employers may set a higher floor, and entitlements differ per parent,
|
||||
so this is modelled per PersonalData row rather than as a single global
|
||||
constant. See PLANNING_ENGINE_SPEC.md §9.2.
|
||||
|
||||
Revision ID: 005
|
||||
Revises: 004
|
||||
Create Date: 2026-09-13
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "005"
|
||||
down_revision: str | None = "004"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
_UPGRADE_SQL = """
|
||||
ALTER TABLE personal_data ADD COLUMN min_vacation_days_per_year INTEGER NOT NULL DEFAULT 20
|
||||
CHECK (min_vacation_days_per_year >= 0 AND min_vacation_days_per_year <= 60);
|
||||
"""
|
||||
|
||||
_DOWNGRADE_SQL = """
|
||||
ALTER TABLE personal_data DROP COLUMN min_vacation_days_per_year;
|
||||
"""
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _UPGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _DOWNGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Add leave_wish.window_mode ('fixed' | 'flexible').
|
||||
|
||||
PLANNING_ENGINE_SPEC.md §10.1 — "när det passar bäst" flexible wishes. For a
|
||||
'flexible' wish the EXISTING window_start_*/window_end_* columns are
|
||||
reinterpreted as the bounding range the allocator searches within, rather
|
||||
than the exact placement; no new columns are needed for the bound itself.
|
||||
Defaults to 'fixed' so every existing row (and every existing construction
|
||||
site) keeps its current, unchanged meaning.
|
||||
|
||||
Revision ID: 006
|
||||
Revises: 005
|
||||
Create Date: 2026-09-13
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "006"
|
||||
down_revision: str | None = "005"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
_UPGRADE_SQL = """
|
||||
ALTER TABLE leave_wish ADD COLUMN window_mode TEXT NOT NULL DEFAULT 'fixed'
|
||||
CHECK (window_mode IN ('fixed','flexible'));
|
||||
"""
|
||||
|
||||
_DOWNGRADE_SQL = """
|
||||
ALTER TABLE leave_wish DROP COLUMN window_mode;
|
||||
"""
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _UPGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
from sqlalchemy import text
|
||||
|
||||
for stmt in [s.strip() for s in _DOWNGRADE_SQL.split(";") if s.strip()]:
|
||||
op.execute(text(stmt))
|
||||
Reference in New Issue
Block a user