Skip to content

Add CopyExt and DocExtensions to correction framework + fix ARCA credit note flow#759

Open
pmenendz wants to merge 4 commits intomainfrom
arca-credit-note
Open

Add CopyExt and DocExtensions to correction framework + fix ARCA credit note flow#759
pmenendz wants to merge 4 commits intomainfrom
arca-credit-note

Conversation

@pmenendz
Copy link
Copy Markdown
Contributor

@pmenendz pmenendz commented Mar 17, 2026

When correcting an ARCA invoice (e.g., standard → credit note), extension values needed to go to two different places:

  • The original doc type ("1" Invoice A) belongs on the preceding document reference
  • The new doc type ("3" Credit Note A) belongs on the invoice itself (inv.Tax.Ext)

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

  • 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 Mar 17, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.05%. Comparing base (b6ed0ec) to head (160943a).

Files with missing lines Patch % Lines
bill/invoice_correct.go 88.88% 1 Missing and 1 partial ⚠️
tax/corrections.go 80.00% 1 Missing and 1 partial ⚠️
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.
📢 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 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 CopyExt to tax.CorrectionDefinition (and schema) and apply it during Invoice.Correct() to copy inv.Tax.Ext into pre.Ext with user overrides taking precedence.
  • Update ARCA correction configuration to use copy_ext instead of requiring explicit extension input during correction.
  • Improve ARCA normalization to clear and re-derive stale/mismatched ar-arca-doc-type values, 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.

Comment thread addons/ar/arca/bill.go Outdated
Comment thread data/addons/ar-arca-v4.json
Comment thread addons/ar/arca/bill_test.go Outdated
@pmenendz pmenendz marked this pull request as ready for review March 17, 2026 18:29
@claude
Copy link
Copy Markdown

claude bot commented Mar 17, 2026

⚠️ Code review skipped — your organization's overage spend limit has been reached.

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.

@pmenendz pmenendz requested a review from samlown March 17, 2026 18:30
@pmenendz pmenendz changed the title Add CopyExt to correction framework and fix ARCA credit note flow Add CopyExt and DocExtensions to correction framework + fix ARCA credit note flow Mar 17, 2026
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 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 CopyExt and DocExtensions to tax.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.

Comment thread bill/invoice_correct.go
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).
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