Files
F-r-ldraledigplannerare/backend/app/models/parental_leave.py
T
jacobh2 e4719cb9ae 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>
2026-09-19 12:27:29 +02:00

92 lines
3.1 KiB
Python

"""Pydantic schemas for parental leave fetch endpoints."""
from datetime import datetime
from typing import Literal
from uuid import UUID
from pydantic import BaseModel, Field
from app.entities.parental_leave import ParentalLeaveFetch, TierData
class TierDataResponse(BaseModel):
sjukpenning_total: int
sjukpenning_used: int
sjukpenning_left: int
lagsta_niva_total: int
lagsta_niva_used: int
lagsta_niva_left: int
@classmethod
def from_entity(cls, td: TierData) -> "TierDataResponse":
return cls(
sjukpenning_total=td.sjukpenning_total,
sjukpenning_used=td.sjukpenning_used,
sjukpenning_left=td.sjukpenning_left,
lagsta_niva_total=td.lagsta_niva_total,
lagsta_niva_used=td.lagsta_niva_used,
lagsta_niva_left=td.lagsta_niva_left,
)
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
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):
id: UUID
personal_data_uuid: UUID
workspace_id: UUID
child_id: UUID
source: str
fetched_at: datetime
total_days: int
days_used: int
days_left: int
reserved_days_total: int
reserved_days_left: int
transferable_days_left: int
dubbeldagar_left: int
tier_data: TierDataResponse
created_at: datetime | None
updated_at: datetime | None
@classmethod
def from_entity(cls, fetch: ParentalLeaveFetch) -> "ParentalLeaveFetchResponse":
return cls(
id=fetch.id,
personal_data_uuid=fetch.personal_data_uuid,
workspace_id=fetch.workspace_id,
child_id=fetch.child_id,
source=fetch.source,
fetched_at=fetch.fetched_at,
total_days=fetch.total_days,
days_used=fetch.days_used,
days_left=fetch.days_left,
reserved_days_total=fetch.reserved_days_total,
reserved_days_left=fetch.reserved_days_left,
transferable_days_left=fetch.transferable_days_left,
dubbeldagar_left=fetch.dubbeldagar_left,
tier_data=TierDataResponse.from_entity(fetch.tier_data),
created_at=fetch.created_at,
updated_at=fetch.updated_at,
)