Skip to content

Commit

Permalink
Merge pull request #27 from invopop/rescale-numbers-up
Browse files Browse the repository at this point in the history
Only rescale numbers up for formatting
  • Loading branch information
samlown authored May 14, 2024
2 parents 627373c + ebf01b1 commit 886710b
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 144 deletions.
5 changes: 3 additions & 2 deletions 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.67.3
github.com/invopop/gobl v0.76.0
github.com/invopop/xmldsig v0.8.0
github.com/magefile/mage v1.14.0
github.com/spf13/cobra v1.7.0
Expand All @@ -19,10 +19,11 @@ require (
github.com/beevik/etree v1.1.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/invopop/validation v0.3.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/otiai10/copy v1.10.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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.67.3 h1:My3e65q+ERZVBEtksjV3nMs5nw+wlOohe8Jptf6vKwA=
github.com/invopop/gobl v0.67.3/go.mod h1:Jau+ajdfUCBPVH9VMor6aeYq3S9o7HuSNm07QxxxomE=
github.com/invopop/gobl v0.76.0 h1:WHGJGe+sqljGkcifQMjxaiiYe8kne2bm3Yv4HUlSqOQ=
github.com/invopop/gobl v0.76.0/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=
github.com/invopop/validation v0.3.0/go.mod h1:qIBG6APYLp2Wu3/96p3idYjP8ffTKVmQBfKiZbw0Hts=
github.com/invopop/xmldsig v0.8.0 h1:W/yRh/HcMSlZrkaVtIeycxmBLssXIfy437yNCvx4gD4=
github.com/invopop/xmldsig v0.8.0/go.mod h1:dc3+2BYNw0vzauyZiOobTltp1t3BbvWSq7ae/F2gdk0=
github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/labstack/echo/v4 v4.9.1 h1:GliPYSpzGKlyOhqIbG8nmHBo3i1saKWFOgh41AN3b+Y=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
Expand Down
3 changes: 1 addition & 2 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ func formatAmount(a *num.Amount) string {
if a == nil {
return ""
}

return a.Rescale(2).String()
return a.RescaleUp(2).String()
}
3 changes: 1 addition & 2 deletions payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/pay"
"github.com/invopop/gobl/regimes/it"
"github.com/invopop/gobl/tax"
)

// datiPagamento contains all data related to the payment of the document.
Expand Down Expand Up @@ -87,7 +86,7 @@ func findCodeModalitaPagamento(key cbc.Key) (string, error) {
return code.String(), nil
}

func findPaymentKeyDefinition(key cbc.Key) *tax.KeyDefinition {
func findPaymentKeyDefinition(key cbc.Key) *cbc.KeyDefinition {
for _, keyDef := range regime.PaymentMeansKeys {
if key == keyDef.Key {
return keyDef
Expand Down
2 changes: 1 addition & 1 deletion regime.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import (
"github.com/invopop/gobl/tax"
)

var regime = tax.RegimeFor(l10n.IT, l10n.CodeEmpty)
var regime = tax.RegimeFor(l10n.IT)
283 changes: 151 additions & 132 deletions test/data/invoice-hotel-private.json
Original file line number Diff line number Diff line change
@@ -1,141 +1,160 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "679a2f25-7483-11ec-9722-7ea2cb436ff6",
"dig": {
"alg": "sha256",
"val": "AAAA"
}
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"type": "standard",
"series": "SAMPLE",
"code": "003",
"issue_date": "2023-05-21",
"currency": "EUR",
"tax": {
"prices_include": "VAT"
},
"supplier": {
"name": "Hotel California",
"tax_id": {
"country": "IT",
"code": "12345678903"
},
"addresses": [
{
"num": "102",
"street": "Via California",
"locality": "Palermo",
"region": "PA",
"code": "33213",
"country": "IT"
}
],
"registration": {
"currency": "EUR",
"office": "RM",
"entry": "123456"
}
},
"customer": {
"name": "Random Person",
"tax_id": {
"country": "GB"
},
"addresses": [
{
"num": "23",
"street": "Main Street",
"locality": "London",
"code": "W1 A2",
"country": "GB"
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "679a2f25-7483-11ec-9722-7ea2cb436ff6",
"dig": {
"alg": "sha256",
"val": "6bdbb4af110f22bad603e55d8703b9ecafcfa9d0b1750b633834add3b618f931"
}
]
},
"lines": [
{
"i": 1,
"quantity": "1",
"item": {
"name": "Tassa di Soggiorno",
"price": "1.00"
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"uuid": "018f76a8-958f-7000-ac84-68b205937de3",
"type": "standard",
"series": "SAMPLE",
"code": "003",
"issue_date": "2023-05-21",
"currency": "EUR",
"tax": {
"prices_include": "VAT"
},
"sum": "1.00",
"taxes": [
{
"cat": "VAT",
"rate": "exempt",
"ext": {
"it-sdi-nature": "N1"
"supplier": {
"name": "Hotel California",
"tax_id": {
"country": "IT",
"type": "business",
"code": "12345678903"
},
"addresses": [
{
"num": "102",
"street": "Via California",
"locality": "Palermo",
"region": "PA",
"code": "33213",
"country": "IT"
}
],
"registration": {
"currency": "EUR",
"office": "RM",
"entry": "123456"
}
}
],
"total": "1.00"
},
{
"i": 2,
"quantity": "1",
"item": {
"name": "Camera Matrimoniale",
"price": "125.00"
},
"sum": "125.00",
"taxes": [
{
"cat": "VAT",
"rate": "intermediate",
"percent": "10.0%"
}
],
"total": "125.00"
}
],
"payment": {
"advances": [
{
"date": "2023-05-01",
"key": "card",
"desc": "deposit",
"amount": "29.00"
}
]
},
"totals": {
"sum": "126.00",
"tax_included": "11.36",
"total": "114.64",
"taxes": {
"categories": [
{
"code": "VAT",
"rates": [
{
"key": "exempt",
"ext": {
"it-sdi-nature": "N1"
"customer": {
"name": "Random Person",
"tax_id": {
"country": "GB"
},
"addresses": [
{
"num": "23",
"street": "Main Street",
"locality": "London",
"code": "W1 A2",
"country": "GB"
}
]
},
"lines": [
{
"i": 1,
"quantity": "1",
"item": {
"name": "Tassa di Soggiorno",
"price": "1.00"
},
"base": "1.00",
"amount": "0.00"
},
{
"key": "intermediate",
"base": "113.6364",
"percent": "10.0%",
"amount": "11.3636"
}
],
"amount": "11.3636"
}
"sum": "1.00",
"taxes": [
{
"cat": "VAT",
"rate": "exempt",
"ext": {
"it-sdi-nature": "N1"
}
}
],
"total": "1.00"
},
{
"i": 2,
"quantity": "1",
"item": {
"name": "Camera Matrimoniale",
"price": "125.00"
},
"sum": "125.00",
"taxes": [
{
"cat": "VAT",
"rate": "intermediate",
"percent": "10.0%"
}
],
"total": "125.00"
},
{
"i": 3,
"quantity": "10",
"item": {
"name": "Camera Matrimoniale",
"price": "75.00"
},
"sum": "750.00",
"taxes": [
{
"cat": "VAT",
"rate": "intermediate",
"percent": "10.0%"
}
],
"total": "750.00"
}
],
"sum": "11.3636"
},
"tax": "11.36",
"total_with_tax": "126.00",
"payable": "126.00",
"advance": "29.00",
"due": "97.00"
"payment": {
"advances": [
{
"date": "2023-05-01",
"key": "card",
"description": "deposit",
"amount": "29.00"
}
]
},
"totals": {
"sum": "876.00",
"tax_included": "79.55",
"total": "796.45",
"taxes": {
"categories": [
{
"code": "VAT",
"rates": [
{
"key": "exempt",
"ext": {
"it-sdi-nature": "N1"
},
"base": "1.00",
"amount": "0.00"
},
{
"key": "intermediate",
"base": "795.45",
"percent": "10.0%",
"amount": "79.55"
}
],
"amount": "79.55"
}
],
"sum": "79.55"
},
"tax": "79.55",
"total_with_tax": "876.00",
"payable": "876.00",
"advance": "29.00",
"due": "847.00"
}
}
}
}
}

0 comments on commit 886710b

Please sign in to comment.