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:
2026-09-14 02:33:03 +02:00
parent 3ca1418d94
commit 76b1e712b9
218 changed files with 29867 additions and 6085 deletions
+63 -46
View File
@@ -27,14 +27,14 @@ from uuid import UUID
from dateutil.relativedelta import relativedelta as _relativedelta
from app.config import settings
from app.entities.break_period import BreakPeriod
from app.entities.child import Child
from app.entities.leave_wish import LeaveWish
from app.entities.parental_leave import ParentalLeaveFetch
from app.entities.personal_data import PersonalData
from app.entities.planned_leave import PlannedLeaveDay
from app.entities.vacation_days import VacationDays
from app.repositories.break_period_repository import BreakPeriodRepository
from app.repositories.child_repository import ChildRepository
from app.repositories.leave_wish_repository import LeaveWishRepository
from app.repositories.parental_leave_repository import ParentalLeaveRepository
from app.repositories.personal_data_repository import PersonalDataRepository
from app.repositories.planned_leave_repository import PlannedLeaveRepository
@@ -69,7 +69,8 @@ class TipsContext:
leave_by_parent: dict[UUID, ParentalLeaveFetch | None] # personal_data_uuid → latest
planned_days: list[PlannedLeaveDay] # all future planned days for workspace
vacation_by_parent: dict[UUID, list[VacationDays]]
break_periods: list[BreakPeriod]
leave_wishes: list[LeaveWish]
today: date # injected for deterministic testing
# Type alias for a rule function.
@@ -213,15 +214,14 @@ async def _rule_stretch_time_at_home(ctx: TipsContext) -> Tip | None:
return None
child = ctx.children[0]
fourth_bday = child.birth_date + _relativedelta(years=4)
today = date.today()
today = ctx.today
window_end = today + timedelta(weeks=4)
for parent in ctx.parents:
parent_window_days = [
d
for d in ctx.planned_days
if d.parent_personal_data_uuid == parent.uuid
and today <= d.date <= window_end
if d.parent_personal_data_uuid == parent.uuid and today <= d.date <= window_end
]
intensity = weekly_intensity(parent_window_days, 4.0)
if intensity < 7:
@@ -277,7 +277,7 @@ async def _rule_skip_fp_first_12_months(ctx: TipsContext) -> Tip | None:
async def _rule_sgi_minimum_after_age_1(ctx: TipsContext) -> Tip | None:
today = date.today()
today = ctx.today
for child in ctx.children:
if not is_child_over_age(child.birth_date, 1):
continue
@@ -299,7 +299,7 @@ async def _rule_sgi_minimum_after_age_1(ctx: TipsContext) -> Tip | None:
async def _rule_wrap_weekend_with_vacation(ctx: TipsContext) -> Tip | None:
if ctx.workspace_planning_goal != "max_money":
return None
today = date.today()
today = ctx.today
look_ahead = today + timedelta(weeks=8)
for parent in ctx.parents:
if parent.salary_type != "monthly":
@@ -331,7 +331,7 @@ async def _rule_wrap_weekend_with_vacation(ctx: TipsContext) -> Tip | None:
async def _rule_wrap_red_days_with_vacation(ctx: TipsContext) -> Tip | None:
if ctx.workspace_planning_goal != "max_money":
return None
today = date.today()
today = ctx.today
look_ahead = today + timedelta(weeks=12)
clusters = red_day_clusters_in_range(today, look_ahead)
if not clusters:
@@ -363,41 +363,59 @@ async def _rule_wrap_red_days_with_vacation(ctx: TipsContext) -> Tip | None:
return None
def _concrete_windows_near_today(wish: LeaveWish, today: date) -> list[tuple[date, date]]:
"""Concretize a recurring wish into the window(s) anchored near `today`.
Only a small neighbourhood of anchor years is considered (last year,
this year, next year) — enough to catch a window that started last
December and wraps into January (see LeaveWish.window_for_year) without
materialising the wish's entire multi-year horizon. Full expansion across
the whole horizon is the allocator's job (PLANNING_ENGINE_SPEC.md §3.2),
not the tips engine's.
"""
windows = []
for year in (today.year - 1, today.year, today.year + 1):
if wish.applies_to_year(year):
windows.append(wish.window_for_year(year))
return windows
async def _rule_long_break_parent_swap(ctx: TipsContext) -> Tip | None:
if len(ctx.parents) < 2 or not ctx.break_periods:
if len(ctx.parents) < 2 or not ctx.leave_wishes:
return None
today = date.today()
for bp in ctx.break_periods:
if bp.end_date < today:
continue
working_days = sum(
1
for i in range((bp.end_date - bp.start_date).days + 1)
if (bp.start_date + timedelta(days=i)).weekday() < 5
)
if working_days == 0:
continue
for parent in ctx.parents:
covered = sum(
today = ctx.today
for wish in ctx.leave_wishes:
for start_date, end_date in _concrete_windows_near_today(wish, today):
if end_date < today:
continue
working_days = sum(
1
for d in ctx.planned_days
if d.parent_personal_data_uuid == parent.uuid
and bp.start_date <= d.date <= bp.end_date
for i in range((end_date - start_date).days + 1)
if (start_date + timedelta(days=i)).weekday() < 5
)
if covered < working_days * 0.5:
other = next(p for p in ctx.parents if p.uuid != parent.uuid)
return Tip(
id="long_break_parent_swap",
severity="info",
message_key="tips.long_break_parent_swap",
data={
"break_name": bp.name,
"start_date": bp.start_date.isoformat(),
"end_date": bp.end_date.isoformat(),
"parent_name": parent.name,
"other_parent_name": other.name,
},
if working_days == 0:
continue
for parent in ctx.parents:
covered = sum(
1
for d in ctx.planned_days
if d.parent_personal_data_uuid == parent.uuid
and start_date <= d.date <= end_date
)
if covered < working_days * 0.5:
other = next(p for p in ctx.parents if p.uuid != parent.uuid)
return Tip(
id="long_break_parent_swap",
severity="info",
message_key="tips.long_break_parent_swap",
data={
"break_name": wish.name,
"start_date": start_date.isoformat(),
"end_date": end_date.isoformat(),
"parent_name": parent.name,
"other_parent_name": other.name,
},
)
return None
@@ -405,9 +423,7 @@ async def _rule_reserve_for_preschool_planning_days(ctx: TipsContext) -> Tip | N
if not ctx.children:
return None
child = ctx.children[0]
buffer_needed = preschool_buffer_needed(
child, settings.rules.preschool_planning_days_per_year
)
buffer_needed = preschool_buffer_needed(child, settings.rules.preschool_planning_days_per_year)
if buffer_needed == 0:
return None
for parent in ctx.parents:
@@ -456,7 +472,7 @@ class TipsService:
child_repo: ChildRepository,
pd_repo: PersonalDataRepository,
vacation_repo: VacationDaysRepository,
break_repo: BreakPeriodRepository,
leave_wish_repo: LeaveWishRepository,
workspace_repo: WorkspaceRepository,
) -> None:
self._leave = leave_repo
@@ -464,7 +480,7 @@ class TipsService:
self._children = child_repo
self._parents = pd_repo
self._vacation = vacation_repo
self._breaks = break_repo
self._leave_wishes = leave_wish_repo
self._workspace_repo = workspace_repo
async def get_tips(self, workspace_id: UUID) -> list[Tip]:
@@ -477,7 +493,7 @@ class TipsService:
parents = await self._parents.list_by_workspace(workspace_id)
children = await self._children.list_by_workspace(workspace_id)
break_periods = await self._breaks.get_by_workspace(workspace_id)
leave_wishes = await self._leave_wishes.get_by_workspace(workspace_id)
today = date.today()
all_planned: list[PlannedLeaveDay] = []
@@ -507,5 +523,6 @@ class TipsService:
leave_by_parent=leave_by_parent,
planned_days=all_planned,
vacation_by_parent=vacation_by_parent,
break_periods=break_periods,
leave_wishes=leave_wishes,
today=today,
)