Skip to content

Commit

Permalink
Fixing support for simplified documents
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Dec 4, 2023
1 parent 04d68a8 commit 043a07b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 8 deletions.
18 changes: 11 additions & 7 deletions items.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion parties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
123 changes: 123 additions & 0 deletions test/data/invoice-simplified.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
}
],
"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"
}
}
}
11 changes: 11 additions & 0 deletions test/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package test_test

import (
"testing"

"github.com/invopop/gobl.fatturapa/test"
)

func TestExamples(t *testing.T) {
test.TestConversion()
}

0 comments on commit 043a07b

Please sign in to comment.