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:
+24
-8
@@ -22,23 +22,15 @@ class LeaveRules(BaseModel):
|
||||
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
total_days_per_child: int = 480
|
||||
sjukpenning_days: int = 390 # income-based tier
|
||||
lagsta_niva_days: int = 90 # flat low-rate tier
|
||||
|
||||
days_per_parent: int = 240 # default joint-custody split
|
||||
reserved_days_per_parent: int = 90 # non-transferable ("reserverade dagar")
|
||||
|
||||
max_dubbeldagar: int = 60 # both parents, same child-day
|
||||
dubbeldagar_months_limit: int = 15 # only within the child's first 15 months
|
||||
|
||||
max_savable_days_at_age_4: int = 96 # age-4 ceiling — per CHILD (pooled across parents)
|
||||
# Age-4 ceiling — per PARENT. The 96-day figure above is a per-child pool;
|
||||
# when a child has two parents, each parent's own savable balance is
|
||||
# capped at half of that (48), not 96 each (which would let a two-parent
|
||||
# family save 192 combined). `app.utils.tip_predicates.resolve_age4_savable_cap`
|
||||
# is the single place that decides which of the two applies.
|
||||
max_savable_days_per_parent_at_age_4: int = 48
|
||||
hard_expiry_age_years: int = 12
|
||||
|
||||
# A couple's per-parent age-4 pooling-loss tip (see
|
||||
@@ -66,10 +58,34 @@ class LeaveRules(BaseModel):
|
||||
# allocator actually enforces (PLANNING_ENGINE_SPEC.md §9.2).
|
||||
min_vacation_days_per_year: int = 20
|
||||
|
||||
@property
|
||||
def total_days_per_child(self) -> int:
|
||||
return self.sjukpenning_days + self.lagsta_niva_days
|
||||
|
||||
@property
|
||||
def days_per_parent(self) -> int:
|
||||
"""Default joint-custody split: half of each tier, summed.
|
||||
|
||||
Derived rather than stored so it can never desync from
|
||||
`sjukpenning_days`/`lagsta_niva_days` if a rule year changes either.
|
||||
"""
|
||||
return self.sjukpenning_days // 2 + self.lagsta_niva_days // 2
|
||||
|
||||
@property
|
||||
def transferable_days_per_parent(self) -> int:
|
||||
return self.days_per_parent - self.reserved_days_per_parent
|
||||
|
||||
@property
|
||||
def max_savable_days_per_parent_at_age_4(self) -> int:
|
||||
"""Age-4 ceiling — per PARENT. `max_savable_days_at_age_4` (96) is a
|
||||
per-child pool; when a child has two parents, each parent's own
|
||||
savable balance is capped at half of that (48), not 96 each (which
|
||||
would let a two-parent family save 192 combined).
|
||||
`app.utils.tip_predicates.resolve_age4_savable_cap` is the single
|
||||
place that decides which of the two applies.
|
||||
"""
|
||||
return self.max_savable_days_at_age_4 // 2
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
|
||||
Reference in New Issue
Block a user