Give the analytics overview a per-parent, per-year balance series

Each parent projection now carries one entry per calendar year from
birth to the fourth birthday: vacation earned, carried in, planned,
left, carried out and expiring under Semesterlagen's 20-day floor and
5-year carry-over, plus parental-leave days used and left at year end
with the age-4 clamp applied in the birthday year. The overview sums
them into per-year totals. Frontend types, mapper and fixtures follow.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XBRLomdLK9jF7wU7a8AA6H
This commit is contained in:
2026-09-19 19:02:02 +02:00
parent dbef997da4
commit 4b802ba0be
14 changed files with 1365 additions and 37 deletions
+82 -1
View File
@@ -5,7 +5,84 @@ from uuid import UUID
from pydantic import BaseModel
from app.services.analytics_service import Age4Projection, WorkspaceOverview
from app.services.analytics_service import (
Age4Projection,
ParentalLeaveYearBalance,
ParentYearBalance,
VacationYearBalance,
WorkspaceOverview,
YearTotals,
)
class VacationYearBalanceResponse(BaseModel):
year: int
earned: int
is_assumed: bool
carried_in: int
planned_use: int
left: int
carried_out: int
expiring: int
@classmethod
def from_entity(cls, v: VacationYearBalance) -> "VacationYearBalanceResponse":
return cls(
year=v.year,
earned=v.earned,
is_assumed=v.is_assumed,
carried_in=v.carried_in,
planned_use=v.planned_use,
left=v.left,
carried_out=v.carried_out,
expiring=v.expiring,
)
class ParentalLeaveYearBalanceResponse(BaseModel):
year: int
sjukpenning_used: int
lagsta_used: int
sjukpenning_left: int
lagsta_left: int
@classmethod
def from_entity(cls, p: ParentalLeaveYearBalance) -> "ParentalLeaveYearBalanceResponse":
return cls(
year=p.year,
sjukpenning_used=p.sjukpenning_used,
lagsta_used=p.lagsta_used,
sjukpenning_left=p.sjukpenning_left,
lagsta_left=p.lagsta_left,
)
class ParentYearBalanceResponse(BaseModel):
personal_data_uuid: UUID
child_id: UUID
year: int
vacation: VacationYearBalanceResponse
parental_leave: ParentalLeaveYearBalanceResponse
@classmethod
def from_entity(cls, p: ParentYearBalance) -> "ParentYearBalanceResponse":
return cls(
personal_data_uuid=p.personal_data_uuid,
child_id=p.child_id,
year=p.year,
vacation=VacationYearBalanceResponse.from_entity(p.vacation),
parental_leave=ParentalLeaveYearBalanceResponse.from_entity(p.parental_leave),
)
class YearTotalsResponse(BaseModel):
year: int
pl_left: int
vacation_left: int
@classmethod
def from_entity(cls, y: YearTotals) -> "YearTotalsResponse":
return cls(year=y.year, pl_left=y.pl_left, vacation_left=y.vacation_left)
class Age4ProjectionResponse(BaseModel):
@@ -20,6 +97,7 @@ class Age4ProjectionResponse(BaseModel):
savable_after_b4: int
expiring_at_b4: int
savable_cap_at_b4: int
year_balances: list[ParentYearBalanceResponse]
@classmethod
def from_entity(cls, p: Age4Projection) -> "Age4ProjectionResponse":
@@ -35,6 +113,7 @@ class Age4ProjectionResponse(BaseModel):
savable_after_b4=p.savable_after_b4,
expiring_at_b4=p.expiring_at_b4,
savable_cap_at_b4=p.savable_cap_at_b4,
year_balances=[ParentYearBalanceResponse.from_entity(yb) for yb in p.year_balances],
)
@@ -45,6 +124,7 @@ class WorkspaceOverviewResponse(BaseModel):
combined_days_used: int
combined_days_left: int
combined_expiring_at_b4: int
year_totals: list[YearTotalsResponse]
@classmethod
def from_entity(cls, overview: WorkspaceOverview) -> "WorkspaceOverviewResponse":
@@ -57,4 +137,5 @@ class WorkspaceOverviewResponse(BaseModel):
combined_days_used=overview.combined_days_used,
combined_days_left=overview.combined_days_left,
combined_expiring_at_b4=overview.combined_expiring_at_b4,
year_totals=[YearTotalsResponse.from_entity(y) for y in overview.year_totals],
)