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
+13 -7
View File
@@ -82,16 +82,10 @@ class WorkspaceService:
self,
workspace_id: UUID,
name: str | None = None,
planning_mode: str | None = None,
) -> Workspace:
ws = await self.get_workspace(workspace_id)
if name is not None:
ws.name = name
if planning_mode is not None:
valid_modes = {"solo", "couple"}
if planning_mode not in valid_modes:
raise ValidationError(f"planning_mode must be one of {valid_modes}")
ws.planning_mode = planning_mode
return await self._ws.update(workspace_id, ws)
async def list_members(self, workspace_id: UUID) -> list[PersonalData]:
@@ -99,9 +93,21 @@ class WorkspaceService:
return await self._pd.list_by_workspace(workspace_id)
async def add_placeholder_parent(self, workspace_id: UUID, display_name: str) -> PersonalData:
"""Create a parent profile without a login (solo planning for a partner)."""
"""Create a parent profile without a login (solo planning for a partner).
Capped at 2 parents per workspace (a child has exactly two legal
parents in this model) — mirrors the same cap enforced on the
invitation-redemption path (`redeem_invitation`).
"""
_validate_display_name(display_name)
await self.get_workspace(workspace_id) # verify workspace exists
existing_members = await self._pd.list_by_workspace(workspace_id)
if len(existing_members) >= 2:
raise ValidationError(
"This workspace already has its maximum number of parents",
message_key="workspace.parents.add.maxReached",
data={},
)
pd = PersonalData(
uuid=uuid4(),
workspace_id=workspace_id,