Skip to content

Commit

Permalink
Merge pull request #390 from invopop/fix-mx-normalize
Browse files Browse the repository at this point in the history
Fix panic when normalizing certain invoices in MX
  • Loading branch information
cavalle authored Oct 14, 2024
2 parents 207db6a + 9acdb2b commit 9d13ffb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- `cbc.Code`: new `Join` and `JoinWith` methods to help concatenate codes.
- `it-sdi-v1`: added CIG and CUP identity type codes.

### Fixed

- `mx`: fixed panic when normalizing an invoice with `tax` but no `ext` inside.

## [v0.201.0]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion regimes/mx/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func normalizeInvoice(inv *bill.Invoice) {
// set.
normalizeParty(inv.Supplier) // first do party
ext := make(tax.Extensions)
if inv.Tax != nil {
if inv.Tax != nil && inv.Tax.Ext != nil {
ext = inv.Tax.Ext
}
if ext.Has(extKeyIssuePlace) {
Expand Down
10 changes: 10 additions & 0 deletions regimes/mx/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func TestNormalizeInvoice(t *testing.T) {
require.NotNil(t, inv.Tax)
assert.Equal(t, tax.ExtValue("21000"), inv.Tax.Ext[cfdi.ExtKeyIssuePlace])
})

t.Run("no ext", func(t *testing.T) {
inv := baseInvoice()
inv.Tax = &bill.Tax{}
require.NoError(t, inv.Calculate())
require.NoError(t, inv.Validate())
require.NotNil(t, inv.Tax)
assert.Equal(t, tax.ExtValue("21000"), inv.Tax.Ext[cfdi.ExtKeyIssuePlace])
})

t.Run("with supplier address code", func(t *testing.T) {
inv := baseInvoice()
delete(inv.Supplier.Ext, cfdi.ExtKeyPostCode)
Expand Down

0 comments on commit 9d13ffb

Please sign in to comment.