Derive the rule constants that are arithmetic on other constants

The per-parent day split was written out twice, once in the allocator's input
loader and once in the persistence layer, each with a comment recalling the
time the two disagreed. They now share one derivation, so they cannot drift
apart again without the shared function moving.

Three constants that were stored and happened to equal arithmetic on their
neighbours — the child's total, the per-parent share, and the per-parent
ceiling at age four — are now computed from them. The figures are unchanged;
what changes is that a future adjustment to a tier total carries into them
instead of quietly leaving them behind.

The shortfall remedies were also split into one method per remedy, matching
the surplus advice alongside them, which had already been written that way.
This commit is contained in:
2026-09-18 01:12:00 +02:00
parent 6a79435baf
commit d245390886
3 changed files with 134 additions and 103 deletions
+6 -7
View File
@@ -14,6 +14,7 @@ from app.repositories.vacation_days_repository import VacationDaysRepository
from app.services.allocation_service import PlanningEngineService, PlanProposal
from app.services.analytics_service import AnalyticsService
from app.utils.errors import DubbeldagError, NotFoundError, ValidationError
from app.utils.tip_predicates import default_tier_pool_share
# Day types that can actually be persisted as a `planned_leave_day` row. A
# proposal may also contain 'free' entries (automatic weekend/red-day
@@ -792,13 +793,11 @@ class PlanningService:
sjuk_total_left = latest.tier_data.sjukpenning_left
lagsta_total_left = latest.tier_data.lagsta_niva_left
else:
# `rules.sjukpenning_days`/`lagsta_niva_days` are the WHOLE
# CHILD's combined tier totals across both parents — halve them
# for this parent's default share, matching
# `AllocationInputLoader.load`'s no-snapshot fallback (Bug A
# fix: the two used to disagree, 390/90 vs. 195/45).
sjuk_total_left = rules.sjukpenning_days // 2
lagsta_total_left = rules.lagsta_niva_days // 2
# No FK snapshot yet: default this parent's share via the shared
# helper — see `default_tier_pool_share` docstring (Bug A fix:
# this and `AllocationInputLoader.load` used to disagree, 390/90
# vs. 195/45).
sjuk_total_left, lagsta_total_left = default_tier_pool_share(rules)
committed_sjuk = await self._repo.count_by_parent_type(parent_uuid, child_id, "sjukpenning")
committed_lagsta = await self._repo.count_by_parent_type(parent_uuid, child_id, "lagsta")