Skip to content

Commit

Permalink
Merge pull request #363 from invopop/v0.200.0-rc2
Browse files Browse the repository at this point in the history
Release v0.200.0-rc2
  • Loading branch information
samlown authored Sep 23, 2024
2 parents 236b872 + 52da20f commit b3892e1
Show file tree
Hide file tree
Showing 50 changed files with 804 additions and 528 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Finally, the `draft` flag has been removed from the header, and much more emphas
- `pt`: moved SAF-T specific extensions to `addons/pt/saft`.
- `it`: moved SDI and FatturaPA extensions to `addons/it/sdi` with key `it-sdi-v1`.
- `gr`: moved MyDATA to `addons/gr/mydata`, key `gr-mydata-v1`.
- `bill.Preceding`: replaced with `org.DocumentRef`.
- `bill.Invoice`: Ordering now using arrays of `org.DocumentRef`.
- `bill.Invoice`: `series` and `code` now use `cbc.Code` and normalization instead of the independent invoice code.

### Added

Expand All @@ -39,6 +42,7 @@ Finally, the `draft` flag has been removed from the header, and much more emphas
- `tax`: `Scenario` now has `Filter` property to set a code function.
- `tax`: `AddonDef` provides support for defining addon extension packs.
- `gr`: `gr-mydata-invoice-type` extension with related tags and scenarios.
- `org`: `DocumentRef` consolidates references to previous documents in a single place.

## [v0.115.1]

Expand Down
3 changes: 2 additions & 1 deletion addons/es/facturae/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package facturae
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/es"
"github.com/invopop/gobl/tax"
"github.com/invopop/validation"
Expand Down Expand Up @@ -57,7 +58,7 @@ func validateInvoiceTax(val any) error {
}

func validateInvoicePreceding(val any) error {
p, ok := val.(*bill.Preceding)
p, ok := val.(*org.DocumentRef)
if !ok {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion addons/es/facturae/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestInvoicePrecedingValidation(t *testing.T) {
err := inv.Validate()
assert.ErrorContains(t, err, "preceding: cannot be blank.")

inv.Preceding = []*bill.Preceding{
inv.Preceding = []*org.DocumentRef{
{
Code: "123TEST",
},
Expand Down
3 changes: 2 additions & 1 deletion addons/es/tbai/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tbai
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/es"
"github.com/invopop/gobl/tax"
"github.com/invopop/validation"
Expand Down Expand Up @@ -38,7 +39,7 @@ func validateInvoice(inv *bill.Invoice) error {
}

func validateInvoicePreceding(val any) error {
p, ok := val.(*bill.Preceding)
p, ok := val.(*org.DocumentRef)
if !ok {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions addons/gr/mydata/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func validateInvoice(inv *bill.Invoice) error {
inv.Type.In(bill.InvoiceTypeCreditNote),
validation.Required,
),
validation.Each(validation.By(validatePreceding)),
validation.Each(validation.By(validateInvoicePreceding)),
validation.Skip,
),
)
Expand Down Expand Up @@ -169,8 +169,8 @@ func validateInvoicePayment(value any) error {
)
}

func validatePreceding(value any) error {
p, ok := value.(*bill.Preceding)
func validateInvoicePreceding(value any) error {
p, ok := value.(*org.DocumentRef)
if !ok || p == nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion addons/gr/mydata/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestSimplifiedInvoiceValidation(t *testing.T) {
func TestPrecedingValidation(t *testing.T) {
inv := validInvoice()

inv.Preceding = []*bill.Preceding{
inv.Preceding = []*org.DocumentRef{
{
Code: "123",
Stamps: []*head.Stamp{
Expand Down
4 changes: 2 additions & 2 deletions addons/mx/cfdi/food_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/invopop/gobl/cal"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/regimes/mx/sat"
"github.com/invopop/gobl/regimes/mx"
"github.com/invopop/validation"
)

Expand Down Expand Up @@ -103,7 +103,7 @@ func (fve *FoodVouchersEmployee) Validate() error {
return validation.ValidateStruct(fve,
validation.Field(&fve.TaxCode,
validation.Required,
validation.By(sat.ValidateTaxCode),
validation.By(mx.ValidateTaxCode),
),
validation.Field(&fve.CURP,
validation.Required,
Expand Down
6 changes: 3 additions & 3 deletions addons/mx/cfdi/fuel_account_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/mx/sat"
"github.com/invopop/gobl/regimes/mx"
"github.com/invopop/gobl/tax"
"github.com/invopop/validation"
)
Expand All @@ -19,7 +19,7 @@ const (
// FuelAccountValidTaxCodes lists of the complement's allowed tax codes
var FuelAccountValidTaxCodes = []any{
tax.CategoryVAT,
sat.TaxCategoryIEPS,
mx.TaxCategoryIEPS,
}

// FuelAccountBalance carries the data to produce a CFDI's "Complemento de
Expand Down Expand Up @@ -112,7 +112,7 @@ func (fal *FuelAccountLine) Validate() error {
validation.Field(&fal.PurchaseDateTime, cal.DateTimeNotZero()),
validation.Field(&fal.VendorTaxCode,
validation.Required,
validation.By(sat.ValidateTaxCode),
validation.By(mx.ValidateTaxCode),
),
validation.Field(&fal.ServiceStationCode,
validation.Required,
Expand Down
14 changes: 7 additions & 7 deletions addons/mx/cfdi/fuel_account_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/invopop/gobl/addons/mx/cfdi"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/regimes/mx/sat"
"github.com/invopop/gobl/regimes/mx"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestCalculate(t *testing.T) {
Percent: num.NewPercentage(16, 2),
},
{
Category: sat.TaxCategoryIEPS,
Category: mx.TaxCategoryIEPS,
Rate: num.NewAmount(59195, 4),
},
},
Expand All @@ -153,7 +153,7 @@ func TestCalculate(t *testing.T) {
Percent: num.NewPercentage(16, 2),
},
{
Category: sat.TaxCategoryIEPS,
Category: mx.TaxCategoryIEPS,
Rate: num.NewAmount(59195, 4),
},
},
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestCalculate(t *testing.T) {
Percent: num.NewPercentage(16, 2),
},
{
Category: sat.TaxCategoryIEPS,
Category: mx.TaxCategoryIEPS,
Rate: num.NewAmount(5451, 4),
},
},
Expand All @@ -201,7 +201,7 @@ func TestCalculate(t *testing.T) {
Percent: num.NewPercentage(16, 2),
},
{
Category: sat.TaxCategoryIEPS,
Category: mx.TaxCategoryIEPS,
Rate: num.NewAmount(5451, 4),
},
},
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestCalculate(t *testing.T) {
Percent: num.NewPercentage(int64(vat*1000), 3),
},
{
Category: sat.TaxCategoryIEPS,
Category: mx.TaxCategoryIEPS,
Rate: num.NewAmount(int64(ieps*10000), 4),
},
},
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestCalculate(t *testing.T) {
Percent: num.NewPercentage(int64(vat*1000), 3),
},
{
Category: sat.TaxCategoryIEPS,
Category: mx.TaxCategoryIEPS,
Rate: num.NewAmount(int64(ieps*1000), 3),
},
},
Expand Down
29 changes: 4 additions & 25 deletions addons/mx/cfdi/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/invopop/gobl/head"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/mx/sat"
"github.com/invopop/gobl/regimes/mx"
"github.com/invopop/gobl/tax"
"github.com/invopop/validation"
)
Expand All @@ -17,27 +17,6 @@ func normalizeInvoice(inv *bill.Invoice) {
normalizeItem(line.Item)
}

// 2024-04-26: copy suppliers post code to invoice, if not already
// set.
if inv.Tax == nil {
inv.Tax = new(bill.Tax)
}
if inv.Tax.Ext == nil {
inv.Tax.Ext = make(tax.Extensions)
}
if inv.Tax.Ext.Has(ExtKeyIssuePlace) {
return
}
if inv.Supplier.Ext.Has(ExtKeyPostCode) {
inv.Tax.Ext[ExtKeyIssuePlace] = inv.Supplier.Ext[ExtKeyPostCode]
return
}
if len(inv.Supplier.Addresses) > 0 {
addr := inv.Supplier.Addresses[0]
if addr.Code != "" {
inv.Tax.Ext[ExtKeyIssuePlace] = tax.ExtValue(addr.Code)
}
}
}

func validateInvoice(inv *bill.Invoice) error {
Expand Down Expand Up @@ -76,7 +55,7 @@ func validateInvoice(inv *bill.Invoice) error {
)
}

func validateInvoiceTax(preceding []*bill.Preceding) validation.RuleFunc {
func validateInvoiceTax(preceding []*org.DocumentRef) validation.RuleFunc {
return func(value any) error {
obj, _ := value.(*bill.Tax)
if obj == nil {
Expand Down Expand Up @@ -156,14 +135,14 @@ func validateInvoiceLine(value any) error {
}

func validateInvoicePreceding(value interface{}) error {
entry, _ := value.(*bill.Preceding)
entry, _ := value.(*org.DocumentRef)
if entry == nil {
return nil
}
return validation.ValidateStruct(entry,
validation.Field(
&entry.Stamps,
head.StampsHas(sat.StampUUID),
head.StampsHas(mx.StampSATUUID),
validation.Skip,
),
)
Expand Down
2 changes: 1 addition & 1 deletion addons/mx/cfdi/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestUsoCFDIScenarioValidation(t *testing.T) {
func TestPrecedingValidation(t *testing.T) {
inv := validInvoice()

inv.Preceding = []*bill.Preceding{
inv.Preceding = []*org.DocumentRef{
{
Code: "123",
Stamps: []*head.Stamp{
Expand Down
9 changes: 0 additions & 9 deletions addons/mx/cfdi/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,4 @@ func normalizeParty(p *org.Party) {
}
}
p.Identities = idents

// 2024-03-14: Migrate Tax ID Zone to extensions "mx-cfdi-post-code"
if p.TaxID != nil && p.TaxID.Zone != "" { //nolint:staticcheck
if p.Ext == nil {
p.Ext = make(tax.Extensions)
}
p.Ext[ExtKeyPostCode] = tax.ExtValue(p.TaxID.Zone) //nolint:staticcheck
p.TaxID.Zone = "" //nolint:staticcheck
}
}
9 changes: 1 addition & 8 deletions addons/mx/cfdi/party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,13 @@ func TestMigratePartyIdentities(t *testing.T) {
Code: "G01",
},
},
TaxID: &tax.Identity{
Country: "MX",
Code: "ZZZ010101ZZZ",
Zone: "65000",
},
}

addon := tax.AddonForKey(cfdi.V4)
addon.Normalizer(customer)

assert.Empty(t, customer.Identities)
assert.Len(t, customer.Ext, 3)
assert.Len(t, customer.Ext, 2)
assert.Equal(t, "608", customer.Ext[cfdi.ExtKeyFiscalRegime].String())
assert.Equal(t, "G01", customer.Ext[cfdi.ExtKeyUse].String())
assert.Equal(t, "65000", customer.Ext[cfdi.ExtKeyPostCode].String())
assert.Empty(t, customer.TaxID.Zone) //nolint:staticcheck
}
8 changes: 4 additions & 4 deletions addons/mx/cfdi/tax_combo.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package cfdi

import (
"github.com/invopop/gobl/regimes/mx/sat"
"github.com/invopop/gobl/regimes/mx"
"github.com/invopop/gobl/tax"
)

func normalizeTaxCombo(tc *tax.Combo) {
var k tax.ExtValue
switch tc.Category {
case sat.TaxCategoryISR:
case mx.TaxCategoryISR:
k = "001"
case tax.CategoryVAT, sat.TaxCategoryRVAT:
case tax.CategoryVAT, mx.TaxCategoryRVAT:
k = "002"
case sat.TaxCategoryIEPS, sat.TaxCategoryRIEPS:
case mx.TaxCategoryIEPS, mx.TaxCategoryRIEPS:
k = "003"
default:
return
Expand Down
Loading

0 comments on commit b3892e1

Please sign in to comment.