Credit days freed by the same sync before checking the balance

A sync deleted the rows a re-plan had dropped only after apply_proposed_days
had already validated, so capacity being freed in the very same call was
never counted. Shortening one period and lengthening another while near the
pool cap read as pure net-new demand and was refused outright, writing
nothing and losing the edit silently.

apply_proposed_days now takes the keys it should delete, credits those rows
back to their tier and to the dubbeldagar quota during the up-front checks,
and performs the deletions in its own write phase. Validation still runs
fully before any write, which is what SQLite's lack of a cross-request
transaction requires.
This commit is contained in:
2026-09-17 18:12:31 +02:00
parent 6cd60887d5
commit c1aa4ae0b0
4 changed files with 505 additions and 31 deletions
+2
View File
@@ -314,6 +314,7 @@ class PlanApplyResponse(BaseModel):
skipped_identical_count: int
skipped_free_count: int
replaced_count: int
deleted_count: int
collisions: list[DayCollisionResponse]
rejections: list[RejectionResponse]
created_days: list[PlannedLeaveDayResponse]
@@ -326,6 +327,7 @@ class PlanApplyResponse(BaseModel):
skipped_identical_count=result.skipped_identical_count,
skipped_free_count=result.skipped_free_count,
replaced_count=result.replaced_count,
deleted_count=result.deleted_count,
collisions=[DayCollisionResponse.from_domain(c) for c in result.collisions],
rejections=[RejectionResponse.from_domain(r) for r in result.rejections],
created_days=[PlannedLeaveDayResponse.from_entity(d) for d in result.created],