Link planned days to their wish, fix the age-4 cap, drop the planning goal

Three changes that together unblock treating a calendar period as one
editable object.

Migration 008 adds `planned_leave_day.wish_id` (nullable, ON DELETE SET NULL)
so a persisted day knows which `leave_wish` produced it, `is_pinned` to mark a
day the user hand-edited, and `leave_wish.target_days` so a period drawn on a
calendar need not be a whole number of weeks. Apply-time identity still keys on
day_type/is_dubbeldag only, so a wish_id-only difference is a metadata update
rather than a collision.

The age-4 savable ceiling was applying the per-child figure of 96 to each
parent's pool, modelling a two-parent family as able to save 192 days past the
child's fourth birthday. `resolve_age4_savable_cap` is now the single place
that decides 48 (couple with two parents) versus 96 (everyone else), and both
AnalyticsService and the allocator read it.

Migration 009 drops `workspace.planning_goal` and `leave_wish.goal_override`.
The allocator's tier-3 policy collapses to one rule; `salary_type` still
branches, since that reflects what a vacation day actually costs a parent
rather than a user preference.
This commit is contained in:
2026-09-15 20:28:06 +02:00
parent 7f516f2cab
commit cc3ced905e
59 changed files with 1427 additions and 740 deletions
@@ -4,8 +4,8 @@ planning engine (see app.services.allocation_service module docstring).
Uses the same sqlite-backed fixtures as the rest of the service test suite
(tests/conftest.py) to seed a realistic workspace and verify the loader nets
out already-committed `planned_leave_day` rows, falls back to default
entitlement when no FK snapshot exists, and reads `planning_mode` /
`planning_goal` off the workspace.
entitlement when no FK snapshot exists, and reads `planning_mode` off the
workspace.
"""
from datetime import date, datetime
@@ -91,7 +91,6 @@ class TestAllocationInputLoader:
Workspace(
id=uuid4(),
name="Familj",
planning_goal="max_money",
planning_mode="couple",
created_at=now,
)
@@ -202,8 +201,10 @@ class TestAllocationInputLoader:
alloc_input = await loader.load(ws.id, today=date(2027, 1, 1))
assert alloc_input.planning_mode == "couple"
assert alloc_input.planning_goal == "max_money"
assert alloc_input.today == date(2027, 1, 1)
# Two parents in a 'couple' workspace -> per-parent age-4 cap (48),
# not the per-child figure (96).
assert alloc_input.age4_savable_cap == 48
pool_with_fetch = alloc_input.pools[(parent_with_fetch.uuid, child.id)]
assert pool_with_fetch.sjukpenning_left == 288 # 290 - 2 committed
@@ -284,9 +285,7 @@ class TestAllocationInputLoader:
leave_wish_repo: SQLiteLeaveWishRepository,
) -> None:
now = datetime.now()
ws = await workspace_repo.create(
Workspace(id=uuid4(), name="Solo", planning_goal="balanced", created_at=now)
)
ws = await workspace_repo.create(Workspace(id=uuid4(), name="Solo", created_at=now))
await personal_data_repo.create(
PersonalData(uuid=uuid4(), workspace_id=ws.id, name="Solo Parent", created_at=now)
)