Fix successive leave adjustments replacing each other instead of adding up - #46
Merged
Conversation
…replacing Reported: 25 days, "+2 wedding", then "−2 booked in error" left 23 days rather than the 25 it started from. manual_adjustment is a running total, but the dialog offered it as a per-correction figure labelled "Manual adjustment (+/−)" and update() assigned rather than added. So the second correction did not cancel the first, it overwrote it: the stored adjustment went 0 → 2 → −2, and the allowance 25 → 27 → 23. The sum itself was never wrong; base + carry-over + adjustment is right. The adjustment fed into it was. HR thinks in corrections, so the API now takes them. adjustmentDelta adds to what is already stored; manualAdjustment keeps setting the total outright for the rare wholesale overwrite. Sending both is refused rather than guessed at. Applying the delta on the server rather than reading-modifying-writing in the client also means two people adjusting the same entitlement cannot silently lose one another's correction. The dialog now asks for the correction and shows the accumulated total beside it, so it is visible that the field adds rather than replaces. Left empty it changes nothing, so saving a base-days edit on its own no longer disturbs the adjustment. The regression test walks the reported numbers exactly and fails on the old behaviour with the reported 23. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported: Lea has 25 days. HR records "+2 wedding" → 27. HR then records "−2, booked in error" → 23, when it should be back to 25.
What was wrong
Not the sum.
getEntitlement()isbase + carry_over + manual_adjustment, which is right. The value fed into it was wrong.manual_adjustmentis a running total, but the dialog offered it as a per-correction figure labelled "Manual adjustment (+/−)", andupdate()assigned rather than added:So the second correction overwrote the first instead of cancelling it:
022-2-2(replaces2)The fix
HR thinks in corrections, so the API now takes them:
adjustmentDeltaadds to the stored total —+2then−2cancel to0, and the allowance returns to 25.manualAdjustmentstill sets it outright, for the rare wholesale overwrite.Applying the delta server-side rather than read-modify-write in the client also means two people adjusting the same entitlement can no longer silently lose one another's correction.
The dialog now asks for the correction and shows the accumulated total beside it, so it is visible that the field adds rather than replaces:
Left empty it changes nothing, so saving a base-days edit on its own no longer disturbs the adjustment — which the old absolute field did every time.
Testing
166 tests, 461 assertions, 0 failures (3 new). The regression test walks your exact numbers and, against the old code, fails with precisely the reported result:
— i.e. 25 + (−2) = 23. eslint 0 errors (no new warnings), stylelint clean, 27/27 vitest, build succeeds. Bundles recompiled in the last commit.
Note on existing data
Rows already saved keep whatever total they hold, and the change history added in #45 starts from here. If Lea currently reads 23, her stored adjustment is
−2; one correction of+2now puts her back to 25 and leaves a recorded reason for it.🤖 Generated with Claude Code