From 1c9346872f922c2f66e4e0b3396380f25cbb447a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luismi=20Cavall=C3=A9?= Date: Fri, 11 Oct 2024 07:22:24 +0000 Subject: [PATCH] Fix panic when normalizing certain invoices in MX --- CHANGELOG.md | 6 ++++++ regimes/mx/invoice.go | 2 +- regimes/mx/invoice_test.go | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e8a4be..ce59eb00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to GOBL will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). See also the [GOBL versions](https://docs.gobl.org/overview/versions) documentation site for more details. +## [v0.201.1] + +### Fixed + +- `mx`: fixed panic when normalizing an invoice with `tax` but no `ext` inside. + ## [v0.201.0] ### Fixed diff --git a/regimes/mx/invoice.go b/regimes/mx/invoice.go index c7a92bdb..9698ee3e 100644 --- a/regimes/mx/invoice.go +++ b/regimes/mx/invoice.go @@ -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) { diff --git a/regimes/mx/invoice_test.go b/regimes/mx/invoice_test.go index c0223988..5ffd1c07 100644 --- a/regimes/mx/invoice_test.go +++ b/regimes/mx/invoice_test.go @@ -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)