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
@@ -32,6 +32,7 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
window_end_month=row["window_end_month"],
window_end_day=row["window_end_day"],
target_weeks=row["target_weeks"],
target_days=row["target_days"],
recurrence=row["recurrence"],
first_year=row["first_year"],
last_year=row["last_year"],
@@ -42,7 +43,6 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
if row["parent_personal_data_uuid"] is not None
else None
),
goal_override=row["goal_override"],
window_mode=row["window_mode"],
created_at=datetime.fromisoformat(row["created_at"]),
updated_at=datetime.fromisoformat(row["updated_at"]),
@@ -57,8 +57,8 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
INSERT INTO leave_wish
(id, workspace_id, child_id, name, name_message_key,
window_start_month, window_start_day, window_end_month, window_end_day,
target_weeks, recurrence, first_year, last_year,
priority, parent_mode, parent_personal_data_uuid, goal_override,
target_weeks, target_days, recurrence, first_year, last_year,
priority, parent_mode, parent_personal_data_uuid,
window_mode, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
@@ -73,6 +73,7 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
item.window_end_month,
item.window_end_day,
item.target_weeks,
item.target_days,
item.recurrence,
item.first_year,
item.last_year,
@@ -83,7 +84,6 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
if item.parent_personal_data_uuid is not None
else None
),
item.goal_override,
item.window_mode,
item.created_at.isoformat(),
item.updated_at.isoformat(),
@@ -114,9 +114,9 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
SET child_id = ?, name = ?, name_message_key = ?,
window_start_month = ?, window_start_day = ?,
window_end_month = ?, window_end_day = ?,
target_weeks = ?, recurrence = ?, first_year = ?, last_year = ?,
target_weeks = ?, target_days = ?, recurrence = ?, first_year = ?, last_year = ?,
priority = ?, parent_mode = ?, parent_personal_data_uuid = ?,
goal_override = ?, window_mode = ?, updated_at = ?
window_mode = ?, updated_at = ?
WHERE id = ?
""",
(
@@ -128,6 +128,7 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
item.window_end_month,
item.window_end_day,
item.target_weeks,
item.target_days,
item.recurrence,
item.first_year,
item.last_year,
@@ -138,7 +139,6 @@ class SQLiteLeaveWishRepository(LeaveWishRepository):
if item.parent_personal_data_uuid is not None
else None
),
item.goal_override,
item.window_mode,
item.updated_at.isoformat(),
str(id),
@@ -25,6 +25,8 @@ class SQLitePlannedLeaveRepository(PlannedLeaveRepository):
date=date.fromisoformat(row["date"]),
day_type=row["day_type"],
is_dubbeldag=bool(row["is_dubbeldag"]),
wish_id=UUID(row["wish_id"]) if row["wish_id"] is not None else None,
is_pinned=bool(row["is_pinned"]),
created_at=datetime.fromisoformat(row["created_at"]),
updated_at=datetime.fromisoformat(row["updated_at"]),
)
@@ -37,8 +39,8 @@ class SQLitePlannedLeaveRepository(PlannedLeaveRepository):
"""
INSERT INTO planned_leave_day
(id, workspace_id, child_id, parent_personal_data_uuid, date,
day_type, is_dubbeldag, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
day_type, is_dubbeldag, wish_id, is_pinned, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
str(item.id),
@@ -48,6 +50,8 @@ class SQLitePlannedLeaveRepository(PlannedLeaveRepository):
item.date.isoformat(),
item.day_type,
int(item.is_dubbeldag),
str(item.wish_id) if item.wish_id is not None else None,
int(item.is_pinned),
item.created_at.isoformat(),
item.updated_at.isoformat(),
),
@@ -67,10 +71,17 @@ class SQLitePlannedLeaveRepository(PlannedLeaveRepository):
cursor = await self._conn.execute(
"""
UPDATE planned_leave_day
SET day_type = ?, is_dubbeldag = ?, updated_at = ?
SET day_type = ?, is_dubbeldag = ?, wish_id = ?, is_pinned = ?, updated_at = ?
WHERE id = ?
""",
(item.day_type, int(item.is_dubbeldag), item.updated_at.isoformat(), str(id)),
(
item.day_type,
int(item.is_dubbeldag),
str(item.wish_id) if item.wish_id is not None else None,
int(item.is_pinned),
item.updated_at.isoformat(),
str(id),
),
)
await self._conn.commit()
if cursor.rowcount == 0:
@@ -24,7 +24,6 @@ class SQLiteWorkspaceRepository(WorkspaceRepository):
return Workspace(
id=UUID(row["id"]),
name=row["name"],
planning_goal=row["planning_goal"],
planning_mode=row["planning_mode"],
created_at=datetime.fromisoformat(row["created_at"]),
)
@@ -33,13 +32,12 @@ class SQLiteWorkspaceRepository(WorkspaceRepository):
item.created_at = item.created_at or datetime.now()
await self._conn.execute(
"""
INSERT INTO workspace (id, name, planning_goal, planning_mode, created_at)
VALUES (?, ?, ?, ?, ?)
INSERT INTO workspace (id, name, planning_mode, created_at)
VALUES (?, ?, ?, ?)
""",
(
str(item.id),
item.name,
item.planning_goal,
item.planning_mode,
item.created_at.isoformat(),
),
@@ -54,8 +52,8 @@ class SQLiteWorkspaceRepository(WorkspaceRepository):
async def update(self, id: UUID, item: Workspace) -> Workspace:
cursor = await self._conn.execute(
"UPDATE workspace SET name = ?, planning_goal = ?, planning_mode = ? WHERE id = ?",
(item.name, item.planning_goal, item.planning_mode, str(id)),
"UPDATE workspace SET name = ?, planning_mode = ? WHERE id = ?",
(item.name, item.planning_mode, str(id)),
)
await self._conn.commit()
if cursor.rowcount == 0: