Skip to content

Commit

Permalink
Support customer post code from address
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Oct 29, 2024
1 parent e205e6d commit d9c9900
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion parties.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ func newReceptor(customer *org.Party, issuePlace string) *Receptor {
}
}

postcode := customer.Ext[cfdi.ExtKeyPostCode].String() // TODO: Drop support for ExtKeyPostCode
if postcode == "" && len(customer.Addresses) > 0 {
postcode = customer.Addresses[0].Code
}

return &Receptor{
Nombre: customer.Name,
Rfc: customer.TaxID.Code.String(),
RegimenFiscalReceptor: customer.Ext[cfdi.ExtKeyFiscalRegime].String(),
UsoCFDI: customer.Ext[cfdi.ExtKeyUse].String(),
DomicilioFiscalReceptor: customer.Ext[cfdi.ExtKeyPostCode].String(),
DomicilioFiscalReceptor: postcode,
}
}
21 changes: 21 additions & 0 deletions parties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/invopop/gobl.cfdi/test"
"github.com/invopop/gobl/addons/mx/cfdi"
"github.com/invopop/gobl/org"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -62,4 +64,23 @@ func TestReceptor(t *testing.T) {
assert.Equal(t, "9014514805", r.NumRegIdTrib)
assert.Equal(t, "COL", r.ResidenciaFiscal)
})

t.Run("should map DomicilioFiscal from customer post code", func(t *testing.T) {
inv, err := test.LoadTestInvoice("invoice-b2b-bare.json")
require.NoError(t, err)

delete(inv.Customer.Ext, cfdi.ExtKeyPostCode)
inv.Customer.Addresses = []*org.Address{{Code: "21000"}}

doc, err := test.GenerateCFDIFrom(inv)
require.NoError(t, err)

r := doc.Receptor

assert.Equal(t, "URE180429TM6", r.Rfc)
assert.Equal(t, "UNIVERSIDAD ROBOTICA ESPAÑOLA", r.Nombre)
assert.Equal(t, "21000", r.DomicilioFiscalReceptor)
assert.Equal(t, "601", r.RegimenFiscalReceptor)
assert.Equal(t, "G01", r.UsoCFDI)
})
}

0 comments on commit d9c9900

Please sign in to comment.