Skip to content

Commit

Permalink
Fix: missing tax totals
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jan 29, 2025
1 parent 10c0f2b commit 53d4a02
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
7 changes: 5 additions & 2 deletions doc/breakdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type taxInfo struct {
}

func newTipoDesglose(gobl *bill.Invoice) *TipoDesglose {
if gobl.Totals == nil || gobl.Totals.Taxes == nil {
return nil
}
catTotal := gobl.Totals.Taxes.Category(tax.CategoryVAT)
if catTotal == nil {
return nil
Expand Down Expand Up @@ -265,7 +268,7 @@ func (t taxInfo) isNoSujeta(r *tax.RateTotal) bool {
if t.customerRates {
return true
}
return r.Percent == nil && r.Ext[tbai.ExtKeyExemption].Code().In(notSubjectExemptionCodes...)
return r.Percent == nil && r.Ext[tbai.ExtKeyExemption].In(notSubjectExemptionCodes...)
}

func (t taxInfo) causaNoSujeta(r *tax.RateTotal) string {
Expand All @@ -276,5 +279,5 @@ func (t taxInfo) causaNoSujeta(r *tax.RateTotal) string {
}

func (taxInfo) isExenta(r *tax.RateTotal) bool {
return r.Percent == nil && !r.Ext[tbai.ExtKeyExemption].Code().In(notSubjectExemptionCodes...)
return r.Percent == nil && !r.Ext[tbai.ExtKeyExemption].In(notSubjectExemptionCodes...)
}
8 changes: 4 additions & 4 deletions doc/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package doc
import (
"github.com/invopop/gobl/addons/es/tbai"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/es"
"github.com/invopop/gobl/tax"
)
Expand Down Expand Up @@ -109,13 +109,13 @@ func newDatosFactura(inv *bill.Invoice) (*DatosFactura, error) {
}, nil
}

func newDescription(notes []*cbc.Note) (string, error) {
func newDescription(notes []*org.Note) (string, error) {
for _, note := range notes {
if note.Key == cbc.NoteKeyGeneral {
if note.Key == org.NoteKeyGeneral {
return note.Text, nil
}
}
return "", validationErr(`notes: missing note with key '%s'`, cbc.NoteKeyGeneral)
return "", validationErr(`notes: missing note with key '%s'`, org.NoteKeyGeneral)
}

func newImporteTotal(inv *bill.Invoice) string {
Expand Down
7 changes: 3 additions & 4 deletions doc/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/invopop/gobl/addons/es/tbai"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cal"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/es"
Expand Down Expand Up @@ -67,8 +66,8 @@ func TestFacturaConversion(t *testing.T) {

t.Run("should fill invoice description from general note", func(t *testing.T) {
goblInvoice := test.LoadInvoice("sample-invoice.json")
goblInvoice.Notes = []*cbc.Note{
{Key: cbc.NoteKeyGeneral, Text: "Description of invoice"},
goblInvoice.Notes = []*org.Note{
{Key: org.NoteKeyGeneral, Text: "Description of invoice"},
}

invoice, _ := doc.NewTicketBAI(goblInvoice, ts, role, doc.ZoneBI)
Expand All @@ -79,7 +78,7 @@ func TestFacturaConversion(t *testing.T) {

t.Run("should return error if no description (general note) found", func(t *testing.T) {
goblInvoice := test.LoadInvoice("sample-invoice.json")
goblInvoice.Notes = []*cbc.Note{}
goblInvoice.Notes = []*org.Note{}

_, err := doc.NewTicketBAI(goblInvoice, ts, role, doc.ZoneBI)

Expand Down
2 changes: 1 addition & 1 deletion doc/parties.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newDestinatario(party *org.Party) (*IDDestinatario, error) {
}

if len(party.Addresses) > 0 && party.Addresses[0].Code != "" {
d.CodigoPostal = party.Addresses[0].Code
d.CodigoPostal = party.Addresses[0].Code.String()
d.Direccion = formatAddress(party.Addresses[0])
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.1

require (
github.com/go-resty/resty/v2 v2.13.1
github.com/invopop/gobl v0.204.2-0.20241105091334-a418e60fb2b5
github.com/invopop/gobl v0.208.0
github.com/invopop/xmldsig v0.10.0
github.com/joho/godotenv v1.5.1
github.com/lestrrat-go/libxml2 v0.0.0-20231124114421-99c71026c2f5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/gobl v0.204.2-0.20241105091334-a418e60fb2b5 h1:MLlwU4olYRx1FFa5pLur6PTTaXdaLfT7gscZ6DjkxTw=
github.com/invopop/gobl v0.204.2-0.20241105091334-a418e60fb2b5/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU=
github.com/invopop/gobl v0.208.0 h1:qy5GHXELMy7qBtvgLL8m4d/aBgBaxq0bdAaae4a2luE=
github.com/invopop/gobl v0.208.0/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/validation v0.7.0 h1:NBPLqvYGmLZLQuk5jh0PbaBBetJW7f2VEk/BTWJkGBU=
Expand Down

0 comments on commit 53d4a02

Please sign in to comment.