Skip to content

Fix inclusive Since comparison for historical tax rates#749

Closed
rilla wants to merge 1 commit intoinvopop:mainfrom
rilla:fix-rate-since-comparison
Closed

Fix inclusive Since comparison for historical tax rates#749
rilla wants to merge 1 commit intoinvopop:mainfrom
rilla:fix-rate-since-comparison

Conversation

@rilla
Copy link
Copy Markdown
Contributor

@rilla rilla commented Mar 2, 2026

Summary

While adding tests for historical rates in the FI regime implemented in #748, I realized that RateDef.Value() used Since.Before(date) (strictly less than) to match historical rates, so an invoice issued on the exact Since date would get the previous rate instead.

Existing regimes with historical rates (DE, CO, ES) define Since as the actual effective date (e.g., Since: 2017-01-01 meaning "from January 1st onwards"). The previous comparison silently shifted that by one day.

Changes

  • Use !Since.After(date) to make Since an inclusive lower bound.
  • Add unit tests for RateDef.Value() covering boundary, nil, and no-match cases

Pre-Review Checklist

  • Opened this PR as a draft
  • Read the CONTRIBUTING.md guide.
  • Performed a self-review of my code.
  • Added thorough tests with at least 90% code coverage.
  • Modified or created example GOBL documents to show my changes in use, if appropriate.
  • Added links to the source of the changes in tax regimes or addons, either structured or in the comments.
  • Run go generate . to ensure that the Schemas and Regime data are up to date.
  • Reviewed and fixed all linter warnings.
  • Been obsessive with pointer nil checks to avoid panics.
  • Updated the CHANGELOG.md with an overview of my changes.
  • Marked this PR as ready for review.

And if you are part of the org:

  • Requested a review from Copilot and fixed or dismissed (with a reason) all the feedback raised.
  • Requested a review from @samlown.

RateDef.Value() used a strictly-less-than comparison
(Since.Before(date)) which meant a rate with Since: 2017-01-01
would only apply from January 2nd. Every regime except Finland
wrote Since dates as the actual effective date, assuming inclusive
semantics. Fix the comparison to use !Since.After(date), making
Since dates inclusive lower bounds.

Also correct Germany's historical rate data, which had several
errors independent of the boundary bug:

- Standard rate in 1993 was 15%, not 16% (16% started April 1998)
- The 2007 increase to 19% took effect January 1, not July 1
- COVID temporary reduction (16%/5%) ended December 31 2020, not
  December 31 2021 — restoration to 19%/7% was January 1 2021
- Reduced rate was 7% since 1983, not 5% since 1993
- Removed redundant 2007 entry for reduced rate (no change occurred)

Add boundary date tests for both Germany and Colombia that verify
the correct rate is applied on, before, and after each transition.
@rilla rilla closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant