Skip to content

Commit

Permalink
Merge pull request #32 from invopop/refactor-fiscal-code
Browse files Browse the repository at this point in the history
Refactoring fiscal and tax code handling
  • Loading branch information
samlown authored Jul 18, 2024
2 parents c3a6baf + efc33d5 commit 52bb724
Show file tree
Hide file tree
Showing 18 changed files with 719 additions and 708 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ jobs:
- name: Check out code
uses: actions/checkout@v3

- name: Prepare .netrc
uses: extractions/netrc@v1
with:
machine: github.com
username: ${{ secrets.GO_MOD_USER }}
password: ${{ secrets.GO_MOD_PASS }}

- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: "1.20.4"
go-version-file: "go.mod"
id: go

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v2
with:
version: v1.55
version: v1.58
20 changes: 4 additions & 16 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: "1.21.5"
id: go

- name: Check out code
uses: actions/checkout@v3

#- name: Configure git for private modules
# run: |
# git config --global url."https://${{ secrets.GO_MOD_USER }}:${{ secrets.GO_MOD_PASS }}@github.com".insteadOf "https://github.com"

- name: Prepare .netrc
uses: extractions/netrc@v1
- name: Set up Go
uses: actions/setup-go@v4
with:
machine: github.com
username: ${{ secrets.GO_MOD_USER }}
password: ${{ secrets.GO_MOD_PASS }}
go-version-file: "go.mod"
id: go

- name: Install Dependencies
env:
GOPROXY: https://proxy.golang.org,direct
GOPRIVATE: github.com/invopop
run: go mod download

- name: Test
Expand Down
15 changes: 0 additions & 15 deletions .golangci.toml

This file was deleted.

30 changes: 30 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
run:
timeout: "120s"

output:
formats:
- format: "colored-line-number"

linters:
enable:
- "gocyclo"
- "unconvert"
- "goimports"
- "govet"
#- "misspell" # doesn't handle multilanguage well
- "nakedret"
- "revive"
- "goconst"
- "unparam"
- "gofmt"
- "errname"
- "zerologlint"

linters-settings:
staticcheck:
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: ["all"]

issues:
exclude-use-default: false
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 52bb724

Please sign in to comment.