Skip to content

Commit

Permalink
Moving to use identity key instead of type
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Nov 21, 2023
1 parent ef2da5b commit e8169eb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
16 changes: 8 additions & 8 deletions addendas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
23 changes: 12 additions & 11 deletions addendas/mabe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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),
Expand Down Expand Up @@ -182,15 +183,15 @@ 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(),
}
}

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(),
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 4 additions & 4 deletions test/data/addenda-mabe.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"identities": [
{
"type": "MABE",
"key": "mx-mabe-provider",
"code": "123456"
}
],
Expand Down Expand Up @@ -53,7 +53,7 @@
"price": "100.00",
"identities": [
{
"type": "MABE",
"key": "mx-mabe-item",
"code": "CODE123"
}
],
Expand Down Expand Up @@ -90,7 +90,7 @@
"code": "9100000000",
"identities": [
{
"type": "MABE-REF1",
"key": "mx-mabe-ref1",
"code": "123456"
}
]
Expand All @@ -112,7 +112,7 @@
],
"identities": [
{
"type": "MABE-PLANT-ID",
"key": "mx-mabe-plant",
"code": "S001"
}
]
Expand Down
11 changes: 4 additions & 7 deletions test/data/bare-minimum-addenda-mabe.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"identities": [
{
"type": "MABE",
"key": "mx-mabe-provider",
"code": "123456"
}
],
Expand Down Expand Up @@ -53,7 +53,7 @@
"price": "100.00",
"identities": [
{
"type": "MABE",
"key": "mx-mabe-item",
"code": "CODE123"
}
],
Expand All @@ -76,7 +76,7 @@
"code": "91000000",
"identities": [
{
"type": "MABE-REF1",
"key": "mx-mabe-ref1",
"code": "900900"
}
]
Expand All @@ -91,7 +91,7 @@
"name": "ESTUFAS 30",
"identities": [
{
"type": "MABE-PLANT-ID",
"key": "mx-mabe-plant",
"code": "S001"
}
]
Expand Down Expand Up @@ -120,9 +120,6 @@
"tax": "32.00",
"total_with_tax": "232.00",
"payable": "232.00"
},
"ext": {
"mx-mabe-reference-1": "900900"
}
}
}

0 comments on commit e8169eb

Please sign in to comment.