Rework balances around per-parent days left and deduce the partner from FK

Manual entry now takes one parent's sjukpenningnivå, lägstanivå and
dubbeldagar left (plus optional reserved days) and derives the rest in
build_snapshot, shared with the scraper. The scraper also reads the
family panel and exposes a partner deduction; with two parents it is
saved as a 'deduced' snapshot (migration 002). Parent count is the single
source of entitlement: one member gets 480 days and 96 savable at age 4,
two get 240 and 48 each. Workspaces are capped at two parents.

Also lands the in-flight squash of migrations 002–011 into the initial
schema and the removal of planning_mode.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-09-19 12:27:29 +02:00
parent 375bc64f2f
commit e4719cb9ae
71 changed files with 5705 additions and 1859 deletions
+17 -10
View File
@@ -1,6 +1,7 @@
"""Pydantic schemas for parental leave fetch endpoints."""
from datetime import datetime
from typing import Literal
from uuid import UUID
from pydantic import BaseModel, Field
@@ -29,19 +30,25 @@ class TierDataResponse(BaseModel):
class ManualFetchRequest(BaseModel):
"""Per-parent "days left" manual entry — everything else (tier totals,
days used, reserved/transferable split) is derived by the same shared
function the FK scraper uses (`app.services.leave_snapshot.build_snapshot`),
so a manually-entered snapshot and a scraped one can never disagree on
how the numbers are derived.
"""
personal_data_uuid: UUID
workspace_id: UUID
child_id: UUID
total_days: int = Field(ge=0, le=480)
days_used: int = Field(ge=0, le=480)
reserved_days_total: int = Field(default=90, ge=0, le=240)
reserved_days_left: int = Field(ge=0, le=240)
transferable_days_left: int = Field(ge=0, le=150)
dubbeldagar_left: int = Field(default=60, ge=0, le=60)
sjukpenning_total: int = Field(default=390, ge=0, le=390)
sjukpenning_used: int = Field(ge=0, le=390)
lagsta_niva_total: int = Field(default=90, ge=0, le=90)
lagsta_niva_used: int = Field(ge=0, le=90)
sjukpenning_left: int = Field(ge=0, le=390)
lagsta_niva_left: int = Field(ge=0, le=90)
dubbeldagar_left: int = Field(ge=0, le=60)
# None -> derived from the transferable-first assumption in `build_snapshot`.
reserved_days_left: int | None = Field(default=None, ge=0, le=90)
# None -> defaults to `rules.total_days_per_child // parent_count`
# (480 solo, 240 with a partner) — see `ManualFetchService.save_manual_entry`.
total_days: int | None = Field(default=None, ge=0, le=480)
source: Literal["manual", "deduced"] = "manual"
class ParentalLeaveFetchResponse(BaseModel):