Skip to content

Add Cl regime - #891

Open
pacots wants to merge 4 commits into
invopop:mainfrom
pacots:cl-regime
Open

pacots wants to merge 4 commits into
invopop:mainfrom
pacots:cl-regime

Conversation

@pacots

@pacots pacots commented Jul 3, 2026 •

Copy link
Copy Markdown

Summary

Adds the initial Chile (CL) tax regime.

This PR focuses on core GOBL regime support for Chile: country metadata, IVA/VAT, RUT tax identity normalization and validation, invoice correction types, generated data, and a minimal example invoice.

Chile-specific SII/DTE behavior is deliberately left out of scope and would be better handled in a future addon.

What's included

  • regimes/cl: initial Chile regime package.
  • Chile regime registration via regimes/regimes.go.
  • Chile regime metadata:
    • CL country code
    • CLP currency
    • America/Santiago timezone
    • VAT as the tax scheme
  • IVA (VAT) tax category:
    • 19% general rate
    • effective from 2003-10-01
    • sourced from Decreto Ley 825, Article 14, including the Ley 19.888 effective-date note
  • Chilean RUT tax identity support:
    • normalization removes separators and optional CL prefix
    • lowercase k is normalized to K
    • validation checks length, numeric body, valid check digit character, and Chilean modulo-11 checksum
  • Invoice correction types:
    • credit notes
    • debit notes
  • Minimal Chile invoice example under examples/cl/.
  • Generated regime, rules, schema, and example output data.
  • CHANGELOG entry.

Tests

Adds tests for:

  • Chile regime metadata.
  • RUT normalization.
  • Valid RUTs with numeric, zero, and K check digits.
  • Invalid RUT checksum.
  • Invalid RUT characters.
  • Invalid RUT length.
  • Empty optional tax identity code behavior.
  • Modulo-11 edge cases through public validation behavior.

Focused checks run locally:

go test ./regimes/cl/... -coverprofile=coverage
go tool cover -func=coverage
golangci-lint run ./regimes/cl/...

go test ./regimes/cl/... reports 94.7% coverage.

Generated data and example outputs were updated with:

go generate .
go test --update ./...

Deliberately deferred to a future SII/DTE addon

These are real Chilean e-invoicing concerns, but they are format/platform-specific and do not belong in this initial regime layer:

  • DTE XML generation/parsing
  • SII transmission, certification, status checks, or API integration
  • CAF, folios, TED, electronic stamps, or PDF417 behavior
  • Chile-specific DTE document type mapping
  • Additional/specific taxes, retentions, and sector-specific taxes
  • Chile-specific invoice-level DTE validation rules
  • Chile-specific rounding rules beyond existing GOBL/currency behavior

No Chile-specific scenario mappings are added in this initial PR.

Sources

Official Chilean sources:

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.

@pacots
pacots marked this pull request as ready for review July 3, 2026 05:52
Copilot AI review requested due to automatic review settings July 3, 2026 05:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds initial core GOBL regime support for Chile (CL), including regime registration, IVA/VAT tax category metadata, RUT tax identity normalization/validation, correction types, and a minimal example invoice with regenerated outputs.

Changes:

  • Register the new CL regime and add generated schema/rules/regime artifacts.
  • Implement Chile RUT normalization + modulo-11 validation rules and tests.
  • Add IVA (VAT) 19% category definition and a minimal CL invoice example (source + generated output), plus a CHANGELOG entry.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
regimes/regimes.go Registers the new cl regime via blank import.
regimes/cl/cl.go Defines and registers the Chile regime metadata, normalization, rules, and correction types.
regimes/cl/cl_test.go Verifies Chile regime definition wiring (country/currency/timezone/tax scheme/corrections).
regimes/cl/tax_categories.go Adds IVA/VAT category definition (general 19% rate effective 2003-10-01) with sources.
regimes/cl/tax_identity.go Implements RUT normalization hook + checksum/format validation for Chile tax identity codes.
regimes/cl/tax_identity_test.go Tests normalization behavior and RUT validity/invalidity cases (including edge cases).
examples/cl/invoice-cl-cl.yaml Adds a minimal Chile invoice input example using RUTs.
examples/cl/out/invoice-cl-cl.json Adds the generated output envelope for the CL invoice example.
data/schemas/tax/regime-code.json Adds CL to the regime code schema enumeration.
data/rules/cl.json Adds generated rules output for CL tax identity validation.
data/regimes/cl.json Adds generated regime definition output for CL.
CHANGELOG.md Documents the addition of the Chile regime in Unreleased.

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

@codecov

codecov Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.91837% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.73%. Comparing base (7a4ad62) to head (d7eccd3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
regimes/cl/tax_identity.go 92.15% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #891   +/-   ##
=======================================
  Coverage   94.73%   94.73%           
=======================================
  Files         316      318    +2     
  Lines       17198    17296   +98     
=======================================
+ Hits        16292    16386   +94     
- Misses        560      562    +2     
- Partials      346      348    +2     

☔ View full report in Codecov by Harness.
📢 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.

@samlown samlown left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this! Looks good. I'd suggest refactoring the assertions to provide more detailed fault messages.

Comment thread regimes/cl/tax_identity.go Outdated
Comment thread regimes/cl/tax_identity.go Outdated
@samlown samlown added the regime Related to a specific regime. label Jul 6, 2026
Copilot AI review requested due to automatic review settings July 12, 2026 23:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

regime Related to a specific regime.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants