Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set proper regime when alternative code is given #399

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- `bill.Invoice` - remove empty taxes instances.
- `tax.Identity` - support Calculate method to normalize IDs.
- `tax.Regime` - properly set regime when alternative codes is given.

## [v0.202.0]

Expand Down
5 changes: 3 additions & 2 deletions tax/regime.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ func (r Regime) GetRegime() l10n.TaxCountryCode {
// that the regime is actually defined. Missing regimes will silently replace
// the current regime with an empty value.
func (r *Regime) SetRegime(country l10n.TaxCountryCode) {
if Regimes().For(country.Code()) == nil {
rd := Regimes().For(country.Code())
if rd == nil {
r.Country = ""
return
}
r.Country = country
r.Country = rd.Country
}

// RegimeDef provides the associated regime definition.
Expand Down
20 changes: 20 additions & 0 deletions tax/regimes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tax_test
import (
"testing"

"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
)
Expand All @@ -19,3 +20,22 @@ func TestRegimesAltCountryCodes(t *testing.T) {
r := tax.RegimeDefFor("GR")
assert.Equal(t, "EL", r.Country.String())
}

func TestSetRegime(t *testing.T) {
tests := []struct {
reg string
exp string
}{
{"ES", "ES"},
{"GR", "EL"},
{"YY", ""},
}

for _, tt := range tests {
t.Run(tt.reg, func(t *testing.T) {
r := new(tax.Regime)
r.SetRegime(l10n.TaxCountryCode(tt.reg))
assert.Equal(t, tt.exp, r.GetRegime().String())
})
}
}
Loading