From 6d8eb2d60f9efa137b60ada3bcc890bdff6570c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luismi=20Cavall=C3=A9?= Date: Fri, 8 Nov 2024 13:53:53 +0000 Subject: [PATCH] Extract PEC from new inbox email field --- address.go | 2 +- body.go | 3 +-- go.mod | 2 +- go.sum | 4 ++-- test/data/invoice-b2g.json | 4 ++-- test/data/invoice-credit-note.json | 12 ++++++------ test/data/invoice-hotel.json | 4 ++-- test/data/invoice-irpef.json | 14 +++++++------- test/data/invoice-simple-with-pec.json | 16 ++++++++-------- test/data/invoice-simple.json | 12 ++++++------ transmission.go | 4 ++-- 11 files changed, 38 insertions(+), 39 deletions(-) diff --git a/address.go b/address.go index 1fa1959..7673b4e 100644 --- a/address.go +++ b/address.go @@ -34,7 +34,7 @@ func newAddress(addr *org.Address) *Address { Country: addr.Country.String(), } if addr.Country == l10n.IT.ISO() { - ad.Code = addr.Code + ad.Code = addr.Code.String() } else { ad.Code = foreignCAP } diff --git a/body.go b/body.go index 3823781..95a47fa 100644 --- a/body.go +++ b/body.go @@ -8,7 +8,6 @@ import ( "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" - "github.com/invopop/gobl/regimes/it" ) const ( @@ -201,7 +200,7 @@ func findCodeTipoDocumento(inv *bill.Invoice) (string, error) { func newDatiBollo(charges []*bill.Charge) *datiBollo { for _, charge := range charges { - if charge.Key == it.ChargeKeyStampDuty { + if charge.Key == bill.ChargeKeyStampDuty { return &datiBollo{ BolloVirtuale: stampDutyCode, ImportoBollo: formatAmount(&charge.Amount), diff --git a/go.mod b/go.mod index c6adba9..412295c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 toolchain go1.22.5 require ( - github.com/invopop/gobl v0.203.0 + github.com/invopop/gobl v0.204.2-0.20241108131916-4aee2eb083c6 github.com/invopop/xmldsig v0.8.0 github.com/lestrrat-go/libxml2 v0.0.0-20240521004304-a75c203ac627 github.com/spf13/cobra v1.8.1 diff --git a/go.sum b/go.sum index 14bfaa7..490663e 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,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.203.0 h1:41aIW+gZfyVcP0G0kz+IX4w8AMSx9EgbnALpn0s9CzA= -github.com/invopop/gobl v0.203.0/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU= +github.com/invopop/gobl v0.204.2-0.20241108131916-4aee2eb083c6 h1:VttHfVmyI1yIGQNswLCZ68vxcUNOJILDPfHJkJp/Vdo= +github.com/invopop/gobl v0.204.2-0.20241108131916-4aee2eb083c6/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= diff --git a/test/data/invoice-b2g.json b/test/data/invoice-b2g.json index 121b2f8..154a92f 100644 --- a/test/data/invoice-b2g.json +++ b/test/data/invoice-b2g.json @@ -106,8 +106,8 @@ "sum": "250.00", "discounts": [ { - "amount": "10.00", - "reason": "Sconto" + "reason": "Sconto", + "amount": "10.00" } ], "taxes": [ diff --git a/test/data/invoice-credit-note.json b/test/data/invoice-credit-note.json index ef5e216..dd92b15 100644 --- a/test/data/invoice-credit-note.json +++ b/test/data/invoice-credit-note.json @@ -130,9 +130,9 @@ "sum": "1800.00", "discounts": [ { + "reason": "Special discount", "percent": "10%", - "amount": "180.00", - "reason": "Special discount" + "amount": "180.00" } ], "taxes": [ @@ -168,19 +168,19 @@ "discounts": [ { "i": 1, + "reason": "10th year anniversary discount", "base": "1720.00", "percent": "50%", - "amount": "860.00", - "reason": "10th year anniversary discount" + "amount": "860.00" } ], "charges": [ { "i": 1, + "reason": "10th year anniversary charge", "base": "1720.00", "percent": "10%", - "amount": "172.00", - "reason": "10th year anniversary charge" + "amount": "172.00" } ], "payment": { diff --git a/test/data/invoice-hotel.json b/test/data/invoice-hotel.json index 7660720..870ec83 100644 --- a/test/data/invoice-hotel.json +++ b/test/data/invoice-hotel.json @@ -104,8 +104,8 @@ "sum": "250.00", "discounts": [ { - "amount": "10.00", - "reason": "Sconto" + "reason": "Sconto", + "amount": "10.00" } ], "taxes": [ diff --git a/test/data/invoice-irpef.json b/test/data/invoice-irpef.json index b275965..61a4d9d 100644 --- a/test/data/invoice-irpef.json +++ b/test/data/invoice-irpef.json @@ -115,9 +115,9 @@ "sum": "1800.00", "discounts": [ { + "reason": "Special discount", "percent": "10%", - "amount": "180.00", - "reason": "Special discount" + "amount": "180.00" } ], "taxes": [ @@ -167,23 +167,23 @@ "discounts": [ { "i": 1, + "reason": "10th year anniversary discount", "base": "1720.00", "percent": "50%", - "amount": "860.00", - "reason": "10th year anniversary discount" + "amount": "860.00" } ], "charges": [ { "i": 1, + "reason": "10th year anniversary charge", "base": "1720.00", "percent": "10%", - "amount": "172.00", - "reason": "10th year anniversary charge" + "amount": "172.00" }, { - "key": "stamp-duty", "i": 2, + "key": "stamp-duty", "amount": "12.34" } ], diff --git a/test/data/invoice-simple-with-pec.json b/test/data/invoice-simple-with-pec.json index 45159fa..1394c14 100644 --- a/test/data/invoice-simple-with-pec.json +++ b/test/data/invoice-simple-with-pec.json @@ -4,7 +4,7 @@ "uuid": "679a2f25-7483-11ec-9722-7ea2cb436ff6", "dig": { "alg": "sha256", - "val": "3a010567cc0f19963f2d6eb35418a11aa2a53dd3abc973bd4136d924e1a83802" + "val": "6e31c1f6fc49342bb71a4b449bf3531ea4bfcf1a383319f3425b0a1f73e639ef" } }, "doc": { @@ -90,7 +90,7 @@ "inboxes": [ { "key": "it-sdi-pec", - "code": "fooo@inbox.com" + "email": "fooo@inbox.com" } ], "addresses": [ @@ -121,9 +121,9 @@ "sum": "1800.00", "discounts": [ { + "reason": "Special discount", "percent": "10%", - "amount": "180.00", - "reason": "Special discount" + "amount": "180.00" } ], "taxes": [ @@ -159,19 +159,19 @@ "discounts": [ { "i": 1, + "reason": "10th year anniversary discount", "base": "1720.00", "percent": "50%", - "amount": "860.00", - "reason": "10th year anniversary discount" + "amount": "860.00" } ], "charges": [ { "i": 1, + "reason": "10th year anniversary charge", "base": "1720.00", "percent": "10%", - "amount": "172.00", - "reason": "10th year anniversary charge" + "amount": "172.00" } ], "payment": { diff --git a/test/data/invoice-simple.json b/test/data/invoice-simple.json index c8168f8..f734fc5 100644 --- a/test/data/invoice-simple.json +++ b/test/data/invoice-simple.json @@ -121,9 +121,9 @@ "sum": "1800.00", "discounts": [ { + "reason": "Special discount", "percent": "10%", - "amount": "180.00", - "reason": "Special discount" + "amount": "180.00" } ], "taxes": [ @@ -160,19 +160,19 @@ "discounts": [ { "i": 1, + "reason": "10th year anniversary discount", "base": "1720.00", "percent": "50%", - "amount": "860.00", - "reason": "10th year anniversary discount" + "amount": "860.00" } ], "charges": [ { "i": 1, + "reason": "10th year anniversary charge", "base": "1720.00", "percent": "10%", - "amount": "172.00", - "reason": "10th year anniversary charge" + "amount": "172.00" } ], "payment": { diff --git a/transmission.go b/transmission.go index f04981e..3dd1db5 100644 --- a/transmission.go +++ b/transmission.go @@ -65,7 +65,7 @@ func codiceDestinatario(cus *org.Party) string { } for _, inbox := range cus.Inboxes { if inbox.Key == sdi.KeyInboxCode { - return inbox.Code + return inbox.Code.String() } } } @@ -79,7 +79,7 @@ func pecDestinatario(cus *org.Party) string { if cus != nil { for _, inbox := range cus.Inboxes { if inbox.Key == sdi.KeyInboxPEC { - return inbox.Code + return inbox.Email } } }