Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: moving to single cbc.Definition structure #441

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Changed

- `tax`: renamed `ExtensionsRequires` to `ExtensionsRequire`, to bring in line with `ExtensionsExclude`.
- `cbc`: refactored `KeyDefinition` and `ValueDefinition` into a single `Definition` object that supports `key` and `code`.
- `tax`: removed `ExtValue` and replaced with `cbc.Code` which is now much more flexible.

### Fixed

Expand Down
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
Loading