Add CopyExt and DocExtensions to correction framework + fix ARCA credit note flow#759
Add CopyExt and DocExtensions to correction framework + fix ARCA credit note flow#759
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #759 +/- ##
==========================================
- Coverage 93.05% 93.05% -0.01%
==========================================
Files 333 333
Lines 17796 17819 +23
==========================================
+ Hits 16560 16581 +21
+ Misses 870 869 -1
- Partials 366 369 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends the tax correction framework with a new CopyExt flag to automatically copy invoice-level tax extensions into the preceding document reference during invoice corrections, and updates the ARCA addon to rely on this behavior while improving doc type normalization consistency.
Changes:
- Add
CopyExttotax.CorrectionDefinition(and schema) and apply it duringInvoice.Correct()to copyinv.Tax.Extintopre.Extwith user overrides taking precedence. - Update ARCA correction configuration to use
copy_extinstead of requiring explicit extension input during correction. - Improve ARCA normalization to clear and re-derive stale/mismatched
ar-arca-doc-typevalues, and expand tests to cover the new behavior and correction flow.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tax/corrections.go |
Adds CopyExt to correction definitions and supports merging it. |
data/schemas/tax/regime-def.json |
Updates JSON schema to include copy_ext in correction definitions. |
data/schemas/tax/addon-def.json |
Updates JSON schema to include copy_ext in correction definitions. |
data/addons/ar-arca-v4.json |
Switches ARCA correction config to copy_ext (removes explicit types/extensions). |
bill/invoice_correct.go |
Implements copying of invoice tax extensions into the preceding reference when CopyExt is enabled. |
addons/ar/arca/bill_test.go |
Updates/extends ARCA tests for normalization consistency and correction flows (including CopyExt behavior). |
addons/ar/arca/bill.go |
Updates ARCA correction definition and adds doc-type consistency check + re-derivation logic. |
CHANGELOG.md |
Documents the new CopyExt feature and ARCA correction-flow fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cd7309f to
fb8798c
Compare
fb8798c to
34614f0
Compare
|
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage. Once credits are available, push a new commit or reopen this pull request to trigger a review. |
Add DocExtensions to correction framework
There was a problem hiding this comment.
Pull request overview
This PR extends the tax correction framework to support routing/copying of extension values during document corrections, and uses those capabilities to fix ARCA (Argentina) invoice → credit/debit note correction behavior (preserving original doc-type on the preceding ref while setting the new doc-type on the corrected invoice).
Changes:
- Add
CopyExtandDocExtensionstotax.CorrectionDefinition, including merge/validation behavior and schema generation support. - Update invoice correction logic to (a) copy invoice tax extensions onto the preceding document ref and (b) route configured extension keys to
inv.Tax.Ext. - Update ARCA addon correction definitions + add/adjust tests and schemas documenting the new fields.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tax/corrections.go |
Adds DocExtensions/CopyExt to correction definitions and exposes helpers (HasDocExtension). |
tax/corrections_test.go |
Adds merge/behavior tests for the new correction-definition fields. |
bill/invoice_correct.go |
Implements extension routing/copying during Invoice.Correct() and includes doc extensions in options schema generation. |
bill/invoice_correct_test.go |
Adds AR-specific correction tests exercising CopyExt + DocExtensions routing. |
addons/ar/arca/bill.go |
Updates ARCA correction definition to use CopyExt + DocExtensions. |
addons/ar/arca/bill_test.go |
Expands/adjusts ARCA validation + correction flow tests to reflect new behavior. |
data/addons/ar-arca-v4.json |
Updates ARCA addon correction config to include doc_extensions and copy_ext. |
data/schemas/tax/regime-def.json |
Adds JSON schema fields for doc_extensions and copy_ext in regime correction definitions. |
data/schemas/tax/addon-def.json |
Adds JSON schema fields for doc_extensions and copy_ext in addon correction definitions. |
CHANGELOG.md |
Documents the new correction-definition fields and the ARCA correction-flow fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cd := inv.correctionDef() | ||
| if cd != nil && cd.CopyExt && inv.Tax != nil && len(inv.Tax.Ext) > 0 { | ||
| // Copy the invoice's tax extensions to preceding, then merge | ||
| // user-provided options on top (so they take precedence). |
When correcting an ARCA invoice (e.g., standard → credit note), extension values needed to go to two different places:
There was no routing mechanism for this. ES addons (SII, Verifactu) have a hack where they loop through preceding refs, find extensions, move them to inv.Tax.Ext, and delete from preceding.
To solve this, I included 2 new fields in CorrectionDefinition:
CopyExt bool : When true, automatically copies the invoice's Tax.Ext to the preceding document reference during correction. User-provided extensions in CorrectionOptions.Ext merge on top (taking precedence).
DocExtensions []cbc.Key: Lists extension keys that should be routed to inv.Tax.Ext (not preceding) when the user provides them in CorrectionOptions.Ext. These keys are stripped from pre.Ext before CopyExt runs, so the original values are preserved in preceding.
Pre-Review Checklist
go generate .to ensure that the Schemas and Regime data are up to date.And if you are part of the org: