From 043a07bd0dabaa50d3931bc4c1f368bbd8074387 Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Mon, 4 Dec 2023 09:30:12 +0000 Subject: [PATCH] Fixing support for simplified documents --- items.go | 18 +++-- parties.go | 5 +- test/data/invoice-simplified.json | 123 ++++++++++++++++++++++++++++++ test/examples_test.go | 11 +++ 4 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 test/data/invoice-simplified.json create mode 100644 test/examples_test.go diff --git a/items.go b/items.go index 277b9f4..6b19138 100644 --- a/items.go +++ b/items.go @@ -47,18 +47,23 @@ func generateLineDetails(inv *bill.Invoice) []*dettaglioLinee { var dl []*dettaglioLinee for _, line := range inv.Lines { - vatTax := line.Taxes.Get(tax.CategoryVAT) - - dl = append(dl, &dettaglioLinee{ + d := &dettaglioLinee{ NumeroLinea: strconv.Itoa(line.Index), Descrizione: line.Item.Name, Quantita: formatAmount(&line.Quantity), PrezzoUnitario: formatAmount(&line.Item.Price), PrezzoTotale: formatAmount(&line.Sum), - AliquotaIVA: formatPercentage(vatTax.Percent), - Natura: vatTax.Ext[it.ExtKeySDINature].String(), ScontoMaggiorazione: extractLinePriceAdjustments(line), - }) + } + if len(line.Taxes) > 0 { + vatTax := line.Taxes.Get(tax.CategoryVAT) + if vatTax != nil { + d.AliquotaIVA = formatPercentage(vatTax.Percent) + d.Natura = vatTax.Ext[it.ExtKeySDINature].String() + } + } + + dl = append(dl, d) } return dl @@ -114,7 +119,6 @@ func findRiferimentoNormativo(rateTotal *tax.RateTotal) string { def := regime.ExtensionDef(it.ExtKeySDINature) nature := rateTotal.Ext[it.ExtKeySDINature] - for _, c := range def.Codes { if c.Code == nature { return c.Name[i18n.IT] diff --git a/parties.go b/parties.go index e504c37..0a51c8e 100644 --- a/parties.go +++ b/parties.go @@ -95,8 +95,11 @@ func newCedentePrestatore(s *org.Party) *supplier { } func newCessionarioCommittente(c *org.Party) *customer { - nc := new(customer) + if c == nil { + return nil + } + nc := new(customer) if len(c.Addresses) > 0 { nc.Sede = newAddress(c.Addresses[0]) } diff --git a/test/data/invoice-simplified.json b/test/data/invoice-simplified.json new file mode 100644 index 0000000..926b00a --- /dev/null +++ b/test/data/invoice-simplified.json @@ -0,0 +1,123 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "679a2f25-7483-11ec-9722-7ea2cb436ff6", + "dig": { + "alg": "sha256", + "val": "427155d9bff1a6df157e956f0850ee880a44c8aa2adc8864e3cd48a758805193" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "type": "standard", + "series": "SAMPLE", + "code": "055", + "issue_date": "2023-12-04", + "currency": "EUR", + "tax": { + "tags": [ + "simplified" + ] + }, + "supplier": { + "name": "MªF. Services", + "tax_id": { + "country": "IT", + "code": "12345678903" + }, + "people": [ + { + "name": { + "given": "GIANCARLO", + "surname": "ROSSI" + } + } + ], + "addresses": [ + { + "num": "1", + "street": "VIALE DELLA LIBERTÀ", + "locality": "ROMA", + "region": "RM", + "code": "00100", + "country": "IT" + } + ], + "emails": [ + { + "addr": "billing@example.com" + } + ], + "telephones": [ + { + "num": "999999999" + } + ], + "registration": { + "capital": "50000.00", + "currency": "EUR", + "office": "RM", + "entry": "123456" + }, + "ext": { + "it-sdi-fiscal-regime": "RF01" + } + }, + "lines": [ + { + "i": 1, + "quantity": "20", + "item": { + "name": "Random products", + "price": "90.00", + "unit": "h" + }, + "sum": "1800.00", + "discounts": [ + { + "percent": "10%", + "amount": "180.00", + "reason": "Special discount" + } + ], + "taxes": [ + { + "cat": "VAT", + "rate": "standard", + "percent": "22.0%" + } + ], + "total": "1620.00" + } + ], + "payment": { + "instructions": { + "key": "card" + } + }, + "totals": { + "sum": "1620.00", + "total": "1620.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "base": "1620.00", + "percent": "22.0%", + "amount": "356.40" + } + ], + "amount": "356.40" + } + ], + "sum": "356.40" + }, + "tax": "356.40", + "total_with_tax": "1976.40", + "payable": "1976.40" + } + } +} diff --git a/test/examples_test.go b/test/examples_test.go new file mode 100644 index 0000000..17e17d5 --- /dev/null +++ b/test/examples_test.go @@ -0,0 +1,11 @@ +package test_test + +import ( + "testing" + + "github.com/invopop/gobl.fatturapa/test" +) + +func TestExamples(t *testing.T) { + test.TestConversion() +}