Skip to content

Commit

Permalink
Refactoring fiscal and tax code handling
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jul 17, 2024
1 parent c3a6baf commit 9d6d5b2
Show file tree
Hide file tree
Showing 12 changed files with 679 additions and 655 deletions.
34 changes: 17 additions & 17 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ var (
provinceRegexp = regexp.MustCompile(`^[A-Z]{2}$`)
)

// address from IndirizzoType
type address struct {
Indirizzo string // Street
NumeroCivico string `xml:",omitempty"` // Number
CAP string // Post Code
Comune string // Locality
Provincia string `xml:",omitempty"` // Region
Nazione string // Country Code
// Address from IndirizzoType
type Address struct {
Street string `xml:"Indirizzo"` // Street
Number string `xml:"NumeroCivico,omitempty"` // Number
Code string `xml:"CAP"` // Post Code
Locality string `xml:"Comune"` // Locality
Region string `xml:"Provincia,omitempty"` // Region
Country string `xml:"Nazione"` // Country Code
}

func newAddress(addr *org.Address) *address {
ad := &address{
Indirizzo: addressStreet(addr),
NumeroCivico: addr.Number,
Comune: addr.Locality,
Provincia: addressRegion(addr),
Nazione: addr.Country.String(),
func newAddress(addr *org.Address) *Address {
ad := &Address{
Street: addressStreet(addr),
Number: addr.Number,
Locality: addr.Locality,
Region: addressRegion(addr),
Country: addr.Country.String(),
}
if addr.Country == l10n.IT {
ad.CAP = addr.Code
ad.Code = addr.Code
} else {
ad.CAP = foreignCAP
ad.Code = foreignCAP
}
return ad
}
Expand Down
6 changes: 3 additions & 3 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAddressRegion(t *testing.T) {
}

out := newAddress(addr)
assert.Equal(t, "RM", out.Provincia)
assert.Equal(t, "RM", out.Region)
})

t.Run("should ignore text name", func(t *testing.T) {
Expand All @@ -34,7 +34,7 @@ func TestAddressRegion(t *testing.T) {
}

out := newAddress(addr)
assert.Empty(t, out.Provincia)
assert.Empty(t, out.Region)
})

t.Run("should ignore foreign addresses", func(t *testing.T) {
Expand All @@ -48,6 +48,6 @@ func TestAddressRegion(t *testing.T) {
}

out := newAddress(addr)
assert.Empty(t, out.Provincia)
assert.Empty(t, out.Region)
})
}
2 changes: 1 addition & 1 deletion fatturapa.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Converter) ConvertFromGOBL(env *gobl.Envelope) (*Document, error) {
FPANamespace: namespaceFatturaPA,
DSigNamespace: namespaceDSig,
XSINamespace: namespaceXSI,
Versione: formatoTransmissione(invoice.Customer),
Versione: formatoTransmissione(invoice),
SchemaLocation: schemaLocation,
FatturaElettronicaHeader: header,
FatturaElettronicaBody: []*fatturaElettronicaBody{body},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/invopop/gobl.fatturapa
go 1.20

require (
github.com/invopop/gobl v0.76.0
github.com/invopop/gobl v0.80.2-0.20240717130326-6f551acf496e
github.com/invopop/xmldsig v0.8.0
github.com/magefile/mage v1.14.0
github.com/spf13/cobra v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/gobl v0.76.0 h1:WHGJGe+sqljGkcifQMjxaiiYe8kne2bm3Yv4HUlSqOQ=
github.com/invopop/gobl v0.76.0/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0=
github.com/invopop/gobl v0.80.2-0.20240717130326-6f551acf496e h1:uz7iSPjO714qsaRW3hszLblRhaHas7E/i3HZ2EnDyx0=
github.com/invopop/gobl v0.80.2-0.20240717130326-6f551acf496e/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0=
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.3.0 h1:o260kbjXzoBO/ypXDSSrCLL7SxEFUXBsX09YTE9AxZw=
Expand Down
15 changes: 6 additions & 9 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import (
// fatturaElettronicaHeader contains all data related to the parties involved
// in the document.
type fatturaElettronicaHeader struct {
DatiTrasmissione *datiTrasmissione `xml:",omitempty"`
CedentePrestatore *supplier `xml:",omitempty"`
CessionarioCommittente *customer `xml:",omitempty"`
DatiTrasmissione *datiTrasmissione `xml:"DatiTrasmissione,omitempty"`
Supplier *Supplier `xml:"CedentePrestatore,omitempty"`
Customer *Customer `xml:"CessionarioCommittente,omitempty"`
}

func newFatturaElettronicaHeader(inv *bill.Invoice, datiTrasmissione *datiTrasmissione) *fatturaElettronicaHeader {
supplier := newCedentePrestatore(inv.Supplier)
customer := newCessionarioCommittente(inv.Customer)

return &fatturaElettronicaHeader{
DatiTrasmissione: datiTrasmissione,
CedentePrestatore: supplier,
CessionarioCommittente: customer,
DatiTrasmissione: datiTrasmissione,
Supplier: newSupplier(inv.Supplier),
Customer: newCustomer(inv.Customer),
}
}
Loading

0 comments on commit 9d6d5b2

Please sign in to comment.