diff --git a/addendas/README.md b/addendas/README.md index 5fae09d..2bc118e 100644 --- a/addendas/README.md +++ b/addendas/README.md @@ -8,11 +8,11 @@ Each of the addendas currently supported are listed below, with instructions on Most of the MABE Addenda fields are determined automatically from the base GOBL Invoice, with the exception of the following: -| MABE Field | GOBL Invoice Value | Description | -| -------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------- | -| Order Code | `ordering.code = "-CODE-"` | Provided by Mabe for the order | -| Provider Code | `supplier.identities = [{"type":"MABE", "code":"-CODE-"}]` | Code issued by Mabe to identify the supplier | -| Delivery Plant | `delivery.receiver.identities = [{"type":"MABE-PLANT-ID","code":"-CODE-"}]` | Delivery Plant ID | -| Item Code | `lines[i].item.identities = [{"type":"MABE","code":"-CODE-"}]` | Article code provided by Mabe | -| Reference 1 | `ordering.identities = [{"type":"MABE-REF1","code":"-CODE-"}]` | Additional code required by Mabe in certain circumstances while ordering. | -| Reference 2 | NA | Always empty as not currently used by Mabe. | +| MABE Field | GOBL Invoice Value | Description | +| -------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------- | +| Order Code | `ordering.code = "-CODE-"` | Provided by Mabe for the order | +| Provider Code | `supplier.identities = [{"key":"mx-mabe-provider", "code":"-CODE-"}]` | Code issued by Mabe to identify the supplier | +| Delivery Plant | `delivery.receiver.identities = [{"key":"mx-mabe-plant","code":"-CODE-"}]` | Delivery Plant Code | +| Item Code | `lines[i].item.identities = [{"key":"mx-mabe-item","code":"-CODE-"}]` | Article code provided by Mabe | +| Reference 1 | `ordering.identities = [{"key":"mx-mabe-ref1","code":"-CODE-"}]` | Additional code required by Mabe in certain circumstances while ordering. | +| Reference 2 | NA | Always empty as not currently used by Mabe. | diff --git a/addendas/mabe.go b/addendas/mabe.go index 89d57dc..d9a4e9e 100644 --- a/addendas/mabe.go +++ b/addendas/mabe.go @@ -31,10 +31,11 @@ const ( // Mabe specific identity codes. const ( - MabeIdentityTypeCode = "MABE" - MabeRef1IdentityTypeCode = "MABE-REF1" - MabeRef2IdentityTypeCode = "MABE-REF2" - MabePlantIDIdentityTypeCode = "MABE-PLANT-ID" + MabeKeyIdentityProvider = "mx-mabe-provider" + MabeKeyIdentityRef1 = "mx-mabe-ref1" + MabeKeyIdentityRef2 = "mx-mabe-ref2" + MabeKeyIdentityPlant = "mx-mabe-plant" + MabeKeyIdentityItem = "mx-mabe-item" ) // MabeFactura is the root element of the Mabe addendum @@ -120,7 +121,7 @@ func isMabe(inv *bill.Invoice) bool { if inv.Supplier == nil { return false } - id := extractIdentity(inv.Supplier.Identities, MabeIdentityTypeCode) + id := extractIdentity(inv.Supplier.Identities, MabeKeyIdentityProvider) return id != cbc.CodeEmpty } @@ -143,7 +144,7 @@ func newMabe(inv *bill.Invoice) (*MabeFactura, error) { Folio: formatMabeFolio(inv), Fecha: inv.IssueDate.String(), OrdenCompra: inv.Ordering.Code, - Referencia1: extractIdentity(inv.Ordering.Identities, MabeRef1IdentityTypeCode).String(), + Referencia1: extractIdentity(inv.Ordering.Identities, MabeKeyIdentityRef1).String(), Referencia2: "NA", Moneda: newMabeMoneda(inv), @@ -182,7 +183,7 @@ func newMabeProveedor(inv *bill.Invoice) *MabeProveedor { if inv.Supplier == nil { return nil } - id := extractIdentity(inv.Supplier.Identities, MabeIdentityTypeCode) + id := extractIdentity(inv.Supplier.Identities, MabeKeyIdentityProvider) return &MabeProveedor{ Codigo: id.String(), } @@ -190,7 +191,7 @@ func newMabeProveedor(inv *bill.Invoice) *MabeProveedor { func newMabeEntrega(inv *bill.Invoice) *MabeEntrega { rec := inv.Delivery.Receiver - id := extractIdentity(rec.Identities, MabePlantIDIdentityTypeCode) + id := extractIdentity(rec.Identities, MabeKeyIdentityPlant) e := &MabeEntrega{ PlantaEntrega: id.String(), } @@ -225,7 +226,7 @@ func newMabeDetalles(inv *bill.Invoice) *[]*MabeDetalle { var detalles []*MabeDetalle for _, line := range inv.Lines { - id := extractIdentity(line.Item.Identities, MabeIdentityTypeCode) + id := extractIdentity(line.Item.Identities, MabeKeyIdentityItem) d := &MabeDetalle{ NoLineaArticulo: line.Index, CodigoArticulo: id.String(), @@ -282,12 +283,12 @@ func formatMabeFolio(inv *bill.Invoice) string { return fmt.Sprintf("%s%s", inv.Series, inv.Code) } -func extractIdentity(ids []*org.Identity, typ cbc.Code) cbc.Code { +func extractIdentity(ids []*org.Identity, key cbc.Key) cbc.Code { if ids == nil { return "" } for _, id := range ids { - if id.Type == typ { + if id.Key == key { return id.Code } } diff --git a/go.mod b/go.mod index 77bb6df..ff7d106 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.cfdi go 1.20 require ( - github.com/invopop/gobl v0.62.2-0.20231121145421-5d7dce0fd42d + github.com/invopop/gobl v0.62.2-0.20231121175846-f10ffeb5a094 github.com/joho/godotenv v1.5.1 github.com/magefile/mage v1.15.0 github.com/spf13/cobra v1.7.0 diff --git a/go.sum b/go.sum index 3cec26c..b0ba4d7 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/invopop/gobl v0.62.2-0.20231121145421-5d7dce0fd42d h1:tPpq1L2YH8IyGS452WCPGlbsbjw8u0okxmuhZ21wZi0= github.com/invopop/gobl v0.62.2-0.20231121145421-5d7dce0fd42d/go.mod h1:sEngvTr2gAxexosO0rmQInVSL8C613TUPvBcFT4xMyM= +github.com/invopop/gobl v0.62.2-0.20231121175846-f10ffeb5a094 h1:jPOc6SxQap9sq01c3LodCQi0NdC5UpfwW0g2r8cQUYg= +github.com/invopop/gobl v0.62.2-0.20231121175846-f10ffeb5a094/go.mod h1:sEngvTr2gAxexosO0rmQInVSL8C613TUPvBcFT4xMyM= github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= github.com/invopop/validation v0.3.0 h1:o260kbjXzoBO/ypXDSSrCLL7SxEFUXBsX09YTE9AxZw= diff --git a/test/data/addenda-mabe.json b/test/data/addenda-mabe.json index 75531da..93f6cfd 100644 --- a/test/data/addenda-mabe.json +++ b/test/data/addenda-mabe.json @@ -24,7 +24,7 @@ }, "identities": [ { - "type": "MABE", + "key": "mx-mabe-provider", "code": "123456" } ], @@ -53,7 +53,7 @@ "price": "100.00", "identities": [ { - "type": "MABE", + "key": "mx-mabe-item", "code": "CODE123" } ], @@ -90,7 +90,7 @@ "code": "9100000000", "identities": [ { - "type": "MABE-REF1", + "key": "mx-mabe-ref1", "code": "123456" } ] @@ -112,7 +112,7 @@ ], "identities": [ { - "type": "MABE-PLANT-ID", + "key": "mx-mabe-plant", "code": "S001" } ] diff --git a/test/data/bare-minimum-addenda-mabe.json b/test/data/bare-minimum-addenda-mabe.json index 045e9f6..8a28890 100644 --- a/test/data/bare-minimum-addenda-mabe.json +++ b/test/data/bare-minimum-addenda-mabe.json @@ -24,7 +24,7 @@ }, "identities": [ { - "type": "MABE", + "key": "mx-mabe-provider", "code": "123456" } ], @@ -53,7 +53,7 @@ "price": "100.00", "identities": [ { - "type": "MABE", + "key": "mx-mabe-item", "code": "CODE123" } ], @@ -76,7 +76,7 @@ "code": "91000000", "identities": [ { - "type": "MABE-REF1", + "key": "mx-mabe-ref1", "code": "900900" } ] @@ -91,7 +91,7 @@ "name": "ESTUFAS 30", "identities": [ { - "type": "MABE-PLANT-ID", + "key": "mx-mabe-plant", "code": "S001" } ] @@ -120,9 +120,6 @@ "tax": "32.00", "total_with_tax": "232.00", "payable": "232.00" - }, - "ext": { - "mx-mabe-reference-1": "900900" } } }