Skip to content

Commit

Permalink
Merge pull request #357 from invopop/release-0.115.1
Browse files Browse the repository at this point in the history
Fixing bug in tax total calculations
  • Loading branch information
samlown authored Sep 10, 2024
2 parents 916f6c4 + 397e4ab commit 3b5ed9a
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to GOBL will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). See also the [GOBL versions](https://docs.gobl.org/overview/versions) documentation site for more details.

## [v0.115.1]

### Fixes

- `tax`: totals calculator was ignoring tax combos with rate and percent, when they should be classed as exempt.

## [v0.115.0]

This one is big...
Expand Down
2 changes: 1 addition & 1 deletion bill/preceding.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Preceding struct {
// Tax period in which the previous invoice had an effect required by some tax regimes and formats.
Period *cal.Period `json:"period,omitempty" jsonschema:"title=Period"`
// Extensions for region specific requirements.
Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Ext"`
Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"`
// Additional semi-structured data that may be useful in specific regions
Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}
Expand Down
2 changes: 1 addition & 1 deletion data/schemas/bill/invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@
},
"ext": {
"$ref": "https://gobl.org/draft-0/tax/extensions",
"title": "Ext",
"title": "Extensions",
"description": "Extensions for region specific requirements."
},
"meta": {
Expand Down
2 changes: 1 addition & 1 deletion data/schemas/org/item.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"ext": {
"$ref": "https://gobl.org/draft-0/tax/extensions",
"title": "Ext",
"title": "Extensions",
"description": "Extension code map for any additional regime specific codes that may be required."
},
"meta": {
Expand Down
2 changes: 1 addition & 1 deletion data/schemas/org/party.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
},
"ext": {
"$ref": "https://gobl.org/draft-0/tax/extensions",
"title": "Ext",
"title": "Extensions",
"description": "Extension code map for any additional regime specific codes that may be required."
},
"meta": {
Expand Down
4 changes: 2 additions & 2 deletions data/schemas/tax/regime.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@
"$ref": "https://gobl.org/draft-0/cbc/key"
},
"type": "array",
"title": "Tag",
"description": "Tag that was applied to the document"
"title": "Tags",
"description": "Array of tags that have been applied to the document."
},
"ext_key": {
"$ref": "https://gobl.org/draft-0/cbc/key",
Expand Down
2 changes: 1 addition & 1 deletion data/schemas/tax/set.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"ext": {
"$ref": "https://gobl.org/draft-0/tax/extensions",
"title": "Ext",
"title": "Extensions",
"description": "Local codes that apply for a given rate or percentage that need to be identified and validated."
}
},
Expand Down
2 changes: 1 addition & 1 deletion data/schemas/tax/total.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"ext": {
"$ref": "https://gobl.org/draft-0/tax/extensions",
"title": "Ext",
"title": "Extensions",
"description": "If the rate is defined with extensions, they'll be used to group by also."
},
"base": {
Expand Down
2 changes: 1 addition & 1 deletion org/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Item struct {
// Country code of where this item was from originally.
Origin l10n.ISOCountryCode `json:"origin,omitempty" jsonschema:"title=Country of Origin"`
// Extension code map for any additional regime specific codes that may be required.
Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Ext"`
Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"`
// Additional meta information that may be useful
Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}
Expand Down
2 changes: 1 addition & 1 deletion org/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Party struct {
// Images that can be used to identify the party visually.
Logos []*Image `json:"logos,omitempty" jsonschema:"title=Logos"`
// Extension code map for any additional regime specific codes that may be required.
Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Ext"`
Ext tax.Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"`
// Any additional semi-structured information that does not fit into the rest of the party.
Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}
Expand Down
2 changes: 1 addition & 1 deletion tax/combo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Combo struct {
// Some countries require an additional surcharge (calculated if rate present).
Surcharge *num.Percentage `json:"surcharge,omitempty" jsonschema:"title=Surcharge" jsonschema_extras:"calculated=true"`
// Local codes that apply for a given rate or percentage that need to be identified and validated.
Ext Extensions `json:"ext,omitempty" jsonschema:"title=Ext"`
Ext Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"`

// Copied from the category definition, implies this tax combo is retained
retained bool `json:"-"`
Expand Down
4 changes: 2 additions & 2 deletions tax/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Scenario struct {
// Type of document, if present.
Types []cbc.Key `json:"type,omitempty" jsonschema:"title=Type"`

// Tag that was applied to the document
Tags []cbc.Key `json:"tags,omitempty" jsonschema:"title=Tag"`
// Array of tags that have been applied to the document.
Tags []cbc.Key `json:"tags,omitempty" jsonschema:"title=Tags"`

// Extension key that must be present in the document.
ExtKey cbc.Key `json:"ext_key,omitempty" jsonschema:"title=Extension Key"`
Expand Down
2 changes: 1 addition & 1 deletion tax/totals.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type RateTotal struct {
// this would be possible.
Country l10n.TaxCountryCode `json:"country,omitempty" jsonschema:"title=Country"`
// If the rate is defined with extensions, they'll be used to group by also.
Ext Extensions `json:"ext,omitempty" jsonschema:"title=Ext"`
Ext Extensions `json:"ext,omitempty" jsonschema:"title=Extensions"`
// Base amount that the percentage is applied to.
Base num.Amount `json:"base" jsonschema:"title=Base"`
// Percentage of the rate. Will be nil when taxes are **exempt**.
Expand Down
3 changes: 0 additions & 3 deletions tax/totals_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ func (tc *TotalCalculator) calculateBaseRateTotals(taxLines []*taxLine, t *Total
// Go through each line and add the total to the base of each tax
for _, tl := range taxLines {
for _, c := range tl.taxes {
if c.Percent == nil && c.Rate.IsEmpty() {
continue // not much to do here!
}
rt := t.rateTotalFor(c, tc.Zero)
rt.Base = tc.matchPrecision(rt.Base, tl.total)
rt.Base = rt.Base.Add(tl.total)
Expand Down
46 changes: 46 additions & 0 deletions tax/totals_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,52 @@ func TestTotalBySumCalculate(t *testing.T) {
Sum: num.MakeAmount(0, 2),
},
},
{
desc: "tax included with exempt rate and no key",
lines: []tax.TaxableLine{
&taxableLine{
taxes: tax.Set{
{
Category: tax.CategoryVAT,
Ext: tax.Extensions{
es.ExtKeyTBAIExemption: "E1",
},
},
},
amount: num.MakeAmount(10000, 2),
},
&taxableLine{
taxes: tax.Set{
{
Category: tax.CategoryVAT,
Ext: tax.Extensions{
es.ExtKeyTBAIExemption: "E1",
},
},
},
amount: num.MakeAmount(2000, 2),
},
},
taxIncluded: tax.CategoryVAT,
want: &tax.Total{
Categories: []*tax.CategoryTotal{
{
Code: tax.CategoryVAT,
Rates: []*tax.RateTotal{
{
Ext: tax.Extensions{
es.ExtKeyTBAIExemption: "E1",
},
Base: num.MakeAmount(12000, 2),
Amount: num.MakeAmount(0, 2),
},
},
Amount: num.MakeAmount(0, 2),
},
},
Sum: num.MakeAmount(0, 2),
},
},
{
desc: "tax included with regular and exempt rate",
lines: []tax.TaxableLine{
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Version string

// VERSION is the current version of the GOBL library.
const VERSION Version = "v0.115.0"
const VERSION Version = "v0.115.1"

// Semver parses and returns semver
func (v Version) Semver() *semver.Version {
Expand Down

0 comments on commit 3b5ed9a

Please sign in to comment.