Track preschool planning days, partner invites and real vacation forfeiture

Three strands of work that grew together across the same settings screen and
API client, so they land as one change.

Per-year preschool planning days ("studiedagar"): new table, repository
(SQLite + Postgres), service, router and migration 007, plus the hooks and
Settings UI to plan and record them per child and year. Allocation now
reserves the recorded figure for a year where one exists and only falls back
to the child-level estimate otherwise, marking that fallback as assumed.

Partner invitations: workspaces issue and list invitations, registration
accepts an invite token to join the inviter's workspace instead of creating a
personal one, and a /join/:token page plus the settings invite panel drive it.

Vacation forfeiture: tips and the dashboard now distinguish days a parent
genuinely loses from days that merely age, so the warning stops firing on
balances that were never at risk.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 11:22:07 +02:00
parent 6904961bb4
commit 0e9b20ec37
88 changed files with 5301 additions and 348 deletions
@@ -19,6 +19,7 @@ from app.entities.leave_wish import LeaveWish
from app.entities.parental_leave import ParentalLeaveFetch, TierData
from app.entities.personal_data import PersonalData
from app.entities.planned_leave import PlannedLeaveDay
from app.entities.preschool_planning_days import PreschoolPlanningDays
from app.entities.vacation_days import VacationDays
from app.entities.workspace import Workspace
from app.repositories_impl.sqlite.child_repository import SQLiteChildRepository
@@ -27,6 +28,9 @@ from app.repositories_impl.sqlite.leave_wish_repository import SQLiteLeaveWishRe
from app.repositories_impl.sqlite.parental_leave_repository import SQLiteParentalLeaveRepository
from app.repositories_impl.sqlite.personal_data_repository import SQLitePersonalDataRepository
from app.repositories_impl.sqlite.planned_leave_repository import SQLitePlannedLeaveRepository
from app.repositories_impl.sqlite.preschool_planning_days_repository import (
SQLitePreschoolPlanningDaysRepository,
)
from app.repositories_impl.sqlite.vacation_days_repository import SQLiteVacationDaysRepository
from app.repositories_impl.sqlite.workspace_repository import SQLiteWorkspaceRepository
from app.services.allocation_service import AllocationInputLoader, Allocator, PlanningEngineService
@@ -41,6 +45,7 @@ def _make_loader(
vacation_repo: SQLiteVacationDaysRepository,
planned_leave_repo: SQLitePlannedLeaveRepository,
leave_wish_repo: SQLiteLeaveWishRepository,
preschool_planning_days_repo: SQLitePreschoolPlanningDaysRepository | None = None,
) -> AllocationInputLoader:
return AllocationInputLoader(
workspace_repo=workspace_repo,
@@ -50,6 +55,7 @@ def _make_loader(
vacation_repo=vacation_repo,
planned_leave_repo=planned_leave_repo,
leave_wish_repo=leave_wish_repo,
preschool_planning_days_repo=preschool_planning_days_repo,
)
@@ -626,3 +632,118 @@ class TestAllocationInputLoader:
with pytest.raises(ValidationError):
await loader.load(ws.id, today=date(2027, 1, 1))
class TestPreschoolPlanningDaysReserve:
"""§Task 1 — `AllocationInputLoader` sources the per-year preschool
reserve from `PreschoolPlanningDaysRepository` rows instead of the flat
`preschool_planning_days_per_year * years` lump sum, using recorded
`taken_days` in preference to `planned_days`, and leaving a (child,
year) pair with no row out of the dict entirely — never defaulting it
to 0 — so `_preschool_reserve_days` falls back to `ChildFacts.
preschool_planning_days_per_year` for it (see that field's docstring).
"""
async def test_recorded_taken_days_wins_over_planned_days(
self,
workspace_repo: SQLiteWorkspaceRepository,
child_repo: SQLiteChildRepository,
personal_data_repo: SQLitePersonalDataRepository,
parental_leave_repo: SQLiteParentalLeaveRepository,
vacation_repo: SQLiteVacationDaysRepository,
planned_leave_repo: SQLitePlannedLeaveRepository,
leave_wish_repo: SQLiteLeaveWishRepository,
preschool_planning_days_repo: SQLitePreschoolPlanningDaysRepository,
) -> None:
now = datetime.now()
ws = await workspace_repo.create(Workspace(id=uuid4(), name="Familj", created_at=now))
await personal_data_repo.create(
PersonalData(uuid=uuid4(), workspace_id=ws.id, name="Parent", created_at=now)
)
child = await child_repo.create(
Child(
id=uuid4(),
workspace_id=ws.id,
name="Barn",
birth_date=date(2025, 1, 1),
preschool_start_date=date(2027, 1, 1),
preschool_planning_days_per_year=6,
created_at=now,
)
)
# Recorded: planned 6, but only 3 actually taken -> 3 must win.
await preschool_planning_days_repo.create(
PreschoolPlanningDays(
id=uuid4(), child_id=child.id, year=2027, planned_days=6, taken_days=3
)
)
loader = _make_loader(
workspace_repo,
child_repo,
personal_data_repo,
parental_leave_repo,
vacation_repo,
planned_leave_repo,
leave_wish_repo,
preschool_planning_days_repo=preschool_planning_days_repo,
)
alloc_input = await loader.load(ws.id, today=date(2027, 1, 1))
assert alloc_input.preschool_reserve_by_year[(child.id, 2027)] == 3
async def test_missing_row_is_absent_not_zero(
self,
workspace_repo: SQLiteWorkspaceRepository,
child_repo: SQLiteChildRepository,
personal_data_repo: SQLitePersonalDataRepository,
parental_leave_repo: SQLiteParentalLeaveRepository,
vacation_repo: SQLiteVacationDaysRepository,
planned_leave_repo: SQLitePlannedLeaveRepository,
leave_wish_repo: SQLiteLeaveWishRepository,
preschool_planning_days_repo: SQLitePreschoolPlanningDaysRepository,
) -> None:
now = datetime.now()
ws = await workspace_repo.create(Workspace(id=uuid4(), name="Familj", created_at=now))
await personal_data_repo.create(
PersonalData(uuid=uuid4(), workspace_id=ws.id, name="Parent", created_at=now)
)
child = await child_repo.create(
Child(
id=uuid4(),
workspace_id=ws.id,
name="Barn",
birth_date=date(2025, 1, 1),
preschool_start_date=date(2027, 1, 1),
preschool_planning_days_per_year=6,
created_at=now,
)
)
# No `preschool_planning_days` row created for (child, 2027) at all.
loader = _make_loader(
workspace_repo,
child_repo,
personal_data_repo,
parental_leave_repo,
vacation_repo,
planned_leave_repo,
leave_wish_repo,
preschool_planning_days_repo=preschool_planning_days_repo,
)
alloc_input = await loader.load(ws.id, today=date(2027, 1, 1))
# Absent, not zero -- `_preschool_reserve_days` is what supplies the
# child-default fallback (6/year), never this dict directly.
assert (child.id, 2027) not in alloc_input.preschool_reserve_by_year
from app.services.allocation_service import _preschool_reserve_days
reserve = _preschool_reserve_days(
next(c for c in alloc_input.children if c.id == child.id),
alloc_input.today,
date(2027, 12, 31),
alloc_input.preschool_reserve_by_year,
)
assert reserve == 6