Skip to content

Add CorrectionNormalizer callback to tax.CorrectionDefinition#815

Open
pmenendz wants to merge 2 commits intomainfrom
arca-correction-normalize
Open

Add CorrectionNormalizer callback to tax.CorrectionDefinition#815
pmenendz wants to merge 2 commits intomainfrom
arca-correction-normalize

Conversation

@pmenendz
Copy link
Copy Markdown
Contributor

@pmenendz pmenendz commented Apr 22, 2026

  • Adds CorrectionNormalizer callback type and Normalize field on tax.CorrectionDefinition, allowing addons to define custom logic for routing extensions between
    the invoice and the preceding document reference during Correct().
  • Adds Extensions.Clone() to tax.Extensions and CorrectionOptionsValue() accessor on bill.Invoice.
  • Implements CorrectionNormalizer in ar-arca-v4 to copy original tax extensions to preceding and route the new doc-type to the invoice.
  • Breaking: Migrates es-verifactu-v1 and es-sii-v1 from the normalizer hack (which moved ExtKeyDocType from preceding.Ext to inv.Tax.Ext on every Calculate()) to CorrectionNormalizer (which routes it during Correct() only). Code that called Calculate() on a manually-constructed invoice with ExtKeyDocType on a preceding document ref and expected it to be moved to inv.Tax.Ext will no longer see that behavior, the extension will remain on preceding.Ext. Really weird case. I don't think anyone is using this.

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.40%. Comparing base (5cf58e9) to head (8027c7c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #815      +/-   ##
==========================================
+ Coverage   92.28%   92.40%   +0.11%     
==========================================
  Files         370      370              
  Lines       23242    23295      +53     
==========================================
+ Hits        21450    21525      +75     
+ Misses       1357     1339      -18     
+ Partials      435      431       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new correction-time normalization hook (CorrectionNormalizer) so addons/regimes can route/adjust tax extensions during Invoice.Correct() (instead of relying on Calculate()-time hacks), along with supporting utilities and migrations in affected addons.

Changes:

  • tax: introduce CorrectionNormalizer + CorrectionDefinition.Normalize, and chain normalizers when merging correction definitions.
  • tax/bill: add Extensions.Clone() and Invoice.CorrectionOptionsValue() to support safe, correction-scoped normalization.
  • Addon migrations: implement Normalize for ARCA v4 and migrate Verifactu/SII to use the new correction hook; adjust tests + changelog accordingly.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tax/extensions.go Adds Extensions.Clone() to allow safe copying of extension maps.
tax/extensions_test.go Tests clone behavior (nil/empty/independent copy).
tax/corrections.go Adds CorrectionNormalizer and CorrectionDefinition.Normalize; chains normalizers in Merge().
tax/corrections_test.go Expands unit tests for correction set lookup, merging, and normalizer chaining.
bill/invoice.go Adds internal correctionOptions storage + CorrectionOptionsValue() accessor for normalizers.
bill/invoice_correct.go Invokes correction normalizer during Correct(), sets preceding earlier, clones option extensions.
bill/invoice_correct_test.go Adds invoice-level tests covering normalization and ensuring options aren’t leaked.
addons/ar/arca/bill_invoice.go Implements ARCA correction normalizer to copy original tax extensions to preceding and route doc-type to invoice.
addons/ar/arca/bill_invoice_test.go Updates correction definition assertions and adds correction-normalization behavior tests.
addons/es/verifactu/bill.go Migrates doc-type routing to CorrectionNormalizer during Correct().
addons/es/verifactu/bill_test.go Adjusts expectations now that preceding extensions aren’t forcibly emptied by Calculate().
addons/es/sii/bill.go Migrates doc-type routing to CorrectionNormalizer during Correct().
addons/es/sii/bill_test.go Adjusts expectations now that preceding extensions aren’t forcibly emptied by Calculate().
data/addons/ar-arca-v4.json Removes explicit correction types from addon data (types still provided by the AR regime).
CHANGELOG.md Documents the new hook, migrations, and extension cloning behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bill/invoice_correct.go Outdated
Comment thread addons/ar/arca/bill_invoice.go
@pmenendz pmenendz force-pushed the arca-correction-normalize branch 2 times, most recently from e18c178 to 92c9e2e Compare April 22, 2026 17:51
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.

2 participants