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
@@ -430,12 +430,15 @@ class TestApplyProposedDaysValidation:
seeded_ids: SeededIds,
) -> None:
"""Bug A regression, third copy: with no FK snapshot at all, this
parent's default tier balance must be their per-parent SHARE (195
sjukpenning / 45 lagsta) of `rules.sjukpenning_days`/`lagsta_niva_days`
(390/90, the WHOLE CHILD's combined total across both parents) — not
the full 390/90, which `AllocationInputLoader.load` also used to
wrongly assume for a single parent before the fix. A batch of exactly
195 sjukpenning days must be accepted; one more must be rejected.
parent's default tier balance must agree with
`AllocationInputLoader.load`'s (both go through the shared
`default_tier_pool_share` helper — see its docstring). `seeded_ids`'s
workspace has exactly ONE member, so the default is the FULL
`rules.sjukpenning_days` (390) — the pool follows actual parent
count, not an unconditional halving (see `app.utils.tip_predicates.
default_tier_pool_share`: a sole parent gets the whole pool, a
partnered one gets half). A batch of exactly 390 sjukpenning days
must be accepted; one more must be rejected.
"""
ws, child, parent = (
seeded_ids.workspace_id,
@@ -445,7 +448,7 @@ class TestApplyProposedDaysValidation:
# No ParentalLeaveFetch created -> exercises the default fallback.
one_too_many = [
ProposedDayInput(date(2026, 1, 1) + timedelta(days=i), parent, child, "sjukpenning")
for i in range(196) # 195 default share + 1 over
for i in range(391) # 390 default share (sole parent) + 1 over
]
result = await planning_service.apply_proposed_days(ws, one_too_many)
@@ -461,7 +464,7 @@ class TestApplyProposedDaysValidation:
)
assert rows == []
exactly_the_share = one_too_many[:195]
exactly_the_share = one_too_many[:390]
result_ok = await planning_service.apply_proposed_days(ws, exactly_the_share)
assert result_ok.accepted is True