Skip to content

Commit

Permalink
Removing unnecessary errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Sep 21, 2023
1 parent 3dbf85d commit 41f515e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 36 deletions.
5 changes: 1 addition & 4 deletions fatturapa.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ func (c *Converter) ConvertFromGOBL(env *gobl.Envelope) (*Document, error) {

datiTrasmissione := c.newDatiTrasmissione(invoice, env)

header, err := newFatturaElettronicaHeader(invoice, datiTrasmissione)
if err != nil {
return nil, err
}
header := newFatturaElettronicaHeader(invoice, datiTrasmissione)

body, err := newFatturaElettronicaBody(invoice)
if err != nil {
Expand Down
14 changes: 4 additions & 10 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ type fatturaElettronicaHeader struct {
CessionarioCommittente *customer `xml:",omitempty"`
}

func newFatturaElettronicaHeader(inv *bill.Invoice, datiTrasmissione *datiTrasmissione) (*fatturaElettronicaHeader, error) {
supplier, err := newCedentePrestatore(inv.Supplier)
if err != nil {
return nil, err
}
customer, err := newCessionarioCommittente(inv.Customer)
if err != nil {
return nil, err
}
func newFatturaElettronicaHeader(inv *bill.Invoice, datiTrasmissione *datiTrasmissione) *fatturaElettronicaHeader {
supplier := newCedentePrestatore(inv.Supplier)
customer := newCessionarioCommittente(inv.Customer)

return &fatturaElettronicaHeader{
DatiTrasmissione: datiTrasmissione,
CedentePrestatore: supplier,
CessionarioCommittente: customer,
}, nil
}
}
32 changes: 12 additions & 20 deletions parties.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package fatturapa

import (
"errors"

"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/it"
Expand Down Expand Up @@ -70,7 +68,7 @@ type contatti struct {
Email string `xml:",omitempty"`
}

func newCedentePrestatore(s *org.Party) (*supplier, error) {
func newCedentePrestatore(s *org.Party) *supplier {
ns := &supplier{
DatiAnagrafici: &datiAnagrafici{
IdFiscaleIVA: &taxID{
Expand All @@ -88,10 +86,10 @@ func newCedentePrestatore(s *org.Party) (*supplier, error) {
ns.Sede = newAddress(s.Addresses[0])
}

return ns, nil
return ns
}

func newCessionarioCommittente(c *org.Party) (*customer, error) {
func newCessionarioCommittente(c *org.Party) *customer {
nc := new(customer)

if len(c.Addresses) > 0 {
Expand All @@ -102,25 +100,19 @@ func newCessionarioCommittente(c *org.Party) (*customer, error) {
Anagrafica: newAnagrafica(c),
}

if c.TaxID == nil {
return nil, errors.New("missing customer TaxID")
}

if c.TaxID.Country == "" {
return nil, errors.New("missing customer TaxID Country Code")
}

if isCodiceFiscale(c.TaxID) {
da.CodiceFiscale = c.TaxID.Code.String()
} else if isEUCountry(c.TaxID.Country) {
da.IdFiscaleIVA = customerFiscaleIVA(c.TaxID, euCitizenTaxCodeDefault)
} else {
da.IdFiscaleIVA = customerFiscaleIVA(c.TaxID, nonEUCitizenTaxCodeDefault)
if c.TaxID != nil {
if isCodiceFiscale(c.TaxID) {
da.CodiceFiscale = c.TaxID.Code.String()
} else if isEUCountry(c.TaxID.Country) {
da.IdFiscaleIVA = customerFiscaleIVA(c.TaxID, euCitizenTaxCodeDefault)
} else {
da.IdFiscaleIVA = customerFiscaleIVA(c.TaxID, nonEUCitizenTaxCodeDefault)
}
}

nc.DatiAnagrafici = da

return nc, nil
return nc
}

func newAnagrafica(party *org.Party) *anagrafica {
Expand Down
4 changes: 2 additions & 2 deletions parties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ func TestPartiesCustomer(t *testing.T) {
assert.Equal(t, "99999999999", c.DatiAnagrafici.IdFiscaleIVA.IdCodice)
})

t.Run("should return error for missing tax ID Country", func(t *testing.T) {
t.Run("should not fail if missing key data", func(t *testing.T) {
env := test.LoadTestFile("invoice-simple.json")
test.ModifyInvoice(env, func(inv *bill.Invoice) {
inv.Customer.TaxID.Country = ""
})

_, err := test.ConvertFromGOBL(env)
require.Error(t, err)
require.NoError(t, err)
})
}

0 comments on commit 41f515e

Please sign in to comment.