Skip to content

Commit

Permalink
Set proper regime when alternative code is given
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Oct 21, 2024
1 parent 15397b4 commit 8304390
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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
6 changes: 6 additions & 0 deletions tax/regimes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ func TestRegimesAltCountryCodes(t *testing.T) {
r := tax.RegimeDefFor("GR")
assert.Equal(t, "EL", r.Country.String())
}

func TestSetRegime(t *testing.T) {
r := new(tax.Regime)
r.SetRegime("GR")
assert.Equal(t, "EL", r.GetRegime().String())
}

0 comments on commit 8304390

Please sign in to comment.