Skip to content

Commit

Permalink
Moving from Key and Value Definitions to a single struct
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Dec 5, 2024
1 parent eb70ac6 commit 4aee03e
Show file tree
Hide file tree
Showing 76 changed files with 1,616 additions and 1,651 deletions.
44 changes: 22 additions & 22 deletions addons/br/nfse/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
ExtKeySpecialRegime = "br-nfse-special-regime"
)

var extensions = []*cbc.KeyDefinition{
var extensions = []*cbc.Definition{
{
Key: ExtKeyCNAE,
Name: i18n.String{
Expand All @@ -45,16 +45,16 @@ var extensions = []*cbc.KeyDefinition{
i18n.EN: "Fiscal Incentive",
i18n.PT: "Incentivo Fiscal",
},
Values: []*cbc.ValueDefinition{
Values: []*cbc.Definition{
{
Value: "1",
Code: "1",
Name: i18n.String{
i18n.EN: "Has incentive",
i18n.PT: "Possui incentivo",
},
},
{
Value: "2",
Code: "2",
Name: i18n.String{
i18n.EN: "Does not have incentive",
i18n.PT: "Não possui incentivo",
Expand All @@ -78,51 +78,51 @@ var extensions = []*cbc.KeyDefinition{
i18n.EN: "ISS Liability",
i18n.PT: "Exigibilidade ISS",
},
Values: []*cbc.ValueDefinition{
Values: []*cbc.Definition{
{
Value: "1",
Code: "1",
Name: i18n.String{
i18n.EN: "Liable",
i18n.PT: "Exigível",
},
},
{
Value: "2",
Code: "2",
Name: i18n.String{
i18n.EN: "Not subject",
i18n.PT: "Não incidência",
},
},
{
Value: "3",
Code: "3",
Name: i18n.String{
i18n.EN: "Exempt",
i18n.PT: "Isenção",
},
},
{
Value: "4",
Code: "4",
Name: i18n.String{
i18n.EN: "Export",
i18n.PT: "Exportação",
},
},
{
Value: "5",
Code: "5",
Name: i18n.String{
i18n.EN: "Immune",
i18n.PT: "Imunidade",
},
},
{
Value: "6",
Code: "6",
Name: i18n.String{
i18n.EN: "Suspended Judicially",
i18n.PT: "Suspensa por Decisão Judicial",
},
},
{
Value: "7",
Code: "7",
Name: i18n.String{
i18n.EN: "Suspended Administratively",
i18n.PT: "Suspensa por Processo Administrativo",
Expand Down Expand Up @@ -181,16 +181,16 @@ var extensions = []*cbc.KeyDefinition{
i18n.EN: "Opting for “Simples Nacional” regime",
i18n.PT: "Optante pelo Simples Nacional",
},
Values: []*cbc.ValueDefinition{
Values: []*cbc.Definition{
{
Value: "1",
Code: "1",
Name: i18n.String{
i18n.EN: "Opt-in",
i18n.PT: "Optante",
},
},
{
Value: "2",
Code: "2",
Name: i18n.String{
i18n.EN: "Opt-out",
i18n.PT: "Não optante",
Expand All @@ -216,44 +216,44 @@ var extensions = []*cbc.KeyDefinition{
i18n.EN: "Special Tax Regime",
i18n.PT: "Regime Especial de Tributação",
},
Values: []*cbc.ValueDefinition{
Values: []*cbc.Definition{
{
Value: "1",
Code: "1",
Name: i18n.String{
i18n.EN: "Municipal micro-enterprise",
i18n.PT: "Microempresa municipal",
},
},
{
Value: "2",
Code: "2",
Name: i18n.String{
i18n.EN: "Estimated",
i18n.PT: "Estimativa",
},
},
{
Value: "3",
Code: "3",
Name: i18n.String{
i18n.EN: "Professional Society",
i18n.PT: "Sociedade de profissionais",
},
},
{
Value: "4",
Code: "4",
Name: i18n.String{
i18n.EN: "Cooperative",
i18n.PT: "Cooperativa",
},
},
{
Value: "5",
Code: "5",
Name: i18n.String{
i18n.EN: "Single micro-entrepreneur (MEI)",
i18n.PT: "Microempreendedor individual (MEI)",
},
},
{
Value: "6",
Code: "6",
Name: i18n.String{
i18n.EN: "Micro-enterprise or Small Business (ME EPP)",
i18n.PT: "Microempresa ou Empresa de Pequeno Porte (ME EPP).",
Expand Down
2 changes: 1 addition & 1 deletion addons/br/nfse/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
IdentityKeyNationalReg = "br-nfse-national-reg"
)

var identities = []*cbc.KeyDefinition{
var identities = []*cbc.Definition{
{
Key: IdentityKeyMunicipalReg,
Name: i18n.String{
Expand Down
3 changes: 2 additions & 1 deletion addons/br/nfse/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/invopop/gobl/addons/br/nfse"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/tax"
Expand Down Expand Up @@ -232,7 +233,7 @@ func TestSuppliersNormalization(t *testing.T) {
tests := []struct {
name string
supplier *org.Party
out tax.ExtValue
out cbc.Code
}{
{
name: "no supplier",
Expand Down
3 changes: 2 additions & 1 deletion addons/br/nfse/tax_combo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/invopop/gobl/addons/br/nfse"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/regimes/br"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestTaxComboNormalization(t *testing.T) {
tests := []struct {
name string
tc *tax.Combo
out tax.ExtValue
out cbc.Code
}{
{
name: "no tax combo",
Expand Down
24 changes: 12 additions & 12 deletions addons/co/dian/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
ExtKeyDebitCode cbc.Key = "co-dian-debit-code"
)

var extensions = []*cbc.KeyDefinition{
var extensions = []*cbc.Definition{
{
Key: ExtKeyMunicipality,
Name: i18n.String{
Expand Down Expand Up @@ -42,9 +42,9 @@ var extensions = []*cbc.KeyDefinition{
i18n.EN: "DIAN correction code for credit notes",
i18n.ES: "Código de corrección DIAN para notas de crédito",
},
Values: []*cbc.ValueDefinition{
Values: []*cbc.Definition{
{
Value: "1",
Code: "1",
Name: i18n.String{
i18n.EN: "Partial refund",
i18n.ES: "Devolución parcial",
Expand All @@ -55,7 +55,7 @@ var extensions = []*cbc.KeyDefinition{
},
},
{
Value: "2",
Code: "2",
Name: i18n.String{
i18n.EN: "Revoked",
i18n.ES: "Anulación",
Expand All @@ -66,7 +66,7 @@ var extensions = []*cbc.KeyDefinition{
},
},
{
Value: "3",
Code: "3",
Name: i18n.String{
i18n.EN: "Discount",
i18n.ES: "Descuento",
Expand All @@ -77,7 +77,7 @@ var extensions = []*cbc.KeyDefinition{
},
},
{
Value: "4",
Code: "4",
Name: i18n.String{
i18n.EN: "Adjustment",
i18n.ES: "Ajuste",
Expand All @@ -88,7 +88,7 @@ var extensions = []*cbc.KeyDefinition{
},
},
{
Value: "5",
Code: "5",
Name: i18n.String{
i18n.EN: "Other",
i18n.ES: "Otros",
Expand All @@ -106,30 +106,30 @@ var extensions = []*cbc.KeyDefinition{
i18n.EN: "DIAN correction code for debit notes",
i18n.ES: "Código de corrección DIAN para notas de débito",
},
Values: []*cbc.ValueDefinition{
Values: []*cbc.Definition{
{
Value: "1",
Code: "1",
Name: i18n.String{
i18n.EN: "Interest",
i18n.ES: "Intereses",
},
},
{
Value: "2",
Code: "2",
Name: i18n.String{
i18n.EN: "Pending charges",
i18n.ES: "Gastos por cobrar",
},
},
{
Value: "3",
Code: "3",
Name: i18n.String{
i18n.EN: "Change in value",
i18n.ES: "Cambio del valor",
},
},
{
Value: "4",
Code: "4",
Name: i18n.String{
i18n.EN: "Other",
i18n.ES: "Otros",
Expand Down
2 changes: 1 addition & 1 deletion addons/co/dian/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
KeyCompanyID cbc.Key = "dian-company-id"
)

var identities = []*cbc.KeyDefinition{
var identities = []*cbc.Definition{
{
Key: IdentityKeyCivilRegister,
Name: i18n.String{
Expand Down
3 changes: 2 additions & 1 deletion addons/co/dian/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/invopop/gobl/addons/co/dian"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cal"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/currency"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
Expand Down Expand Up @@ -175,7 +176,7 @@ func TestBasicCreditNoteValidation(t *testing.T) {
err = inv.Validate()
assert.NoError(t, err)
assert.Contains(t, inv.Preceding[0].Ext, dian.ExtKeyCreditCode)
assert.Equal(t, inv.Preceding[0].Ext[dian.ExtKeyCreditCode], tax.ExtValue("2"))
assert.Equal(t, inv.Preceding[0].Ext[dian.ExtKeyCreditCode], cbc.Code("2"))

inv.Preceding[0].Ext["foo"] = "bar"
err = inv.Validate()
Expand Down
5 changes: 3 additions & 2 deletions addons/de/xrechnung/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package xrechnung
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/untdid"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/tax"
"github.com/invopop/validation"
)

// BR-DE-17 - restricted subset of UNTDID document type codes
var validInvoiceUNTDIDDocumentTypeValues = []tax.ExtValue{
var validInvoiceUNTDIDDocumentTypeValues = []cbc.Code{
"326", // Partial
"380", // Commercial
"384", // Corrected
Expand Down Expand Up @@ -47,7 +48,7 @@ func validateInvoiceTax(value any) error {
}
return validation.ValidateStruct(tx,
validation.Field(&tx.Ext,
tax.ExtensionsHasValues(untdid.ExtKeyTaxCategory, validInvoiceUNTDIDDocumentTypeValues...),
tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, validInvoiceUNTDIDDocumentTypeValues...),
validation.Skip,
),
)
Expand Down
Loading

0 comments on commit 4aee03e

Please sign in to comment.