Skip to content

Commit

Permalink
MX: Fix RFC checks with symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Oct 31, 2024
1 parent 8bbfb25 commit 3e42b81
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 49 deletions.
5 changes: 4 additions & 1 deletion addons/mx/cfdi/food_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type FoodVouchers struct {
// one of the customer's employees. It maps to one `Concepto` node in the CFDI's
// complement.
type FoodVouchersLine struct {
// Line number starting from 1 (calculated).
Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"`
// Identifier of the e-wallet that received the food voucher (maps to `Identificador`).
EWalletID cbc.Code `json:"e_wallet_id" jsonschema:"title=E-wallet Identifier"`
// Date and time of the food voucher's issue (maps to `Fecha`).
Expand Down Expand Up @@ -123,7 +125,8 @@ func (fve *FoodVouchersEmployee) Validate() error {
func (fvc *FoodVouchers) Calculate() error {
fvc.Total = num.MakeAmount(0, FoodVouchersFinalPrecision)

for _, l := range fvc.Lines {
for i, l := range fvc.Lines {
l.Index = i + 1
l.Amount = l.Amount.Rescale(FoodVouchersFinalPrecision)

fvc.Total = fvc.Total.Add(l.Amount)
Expand Down
6 changes: 5 additions & 1 deletion addons/mx/cfdi/fuel_account_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type FuelAccountBalance struct {
// issued by the invoice's supplier. It maps to one
// `ConceptoEstadoDeCuentaCombustible` node in the CFDI's complement.
type FuelAccountLine struct {
// Index of the line starting from 1 (calculated)
Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"`
// Identifier of the e-wallet used to make the purchase (maps to `Identificador`).
EWalletID cbc.Code `json:"e_wallet_id" jsonschema:"title=E-wallet Identifier"`
// Date and time of the purchase (maps to `Fecha`).
Expand Down Expand Up @@ -113,6 +115,7 @@ func (fal *FuelAccountLine) Validate() error {
validation.Field(&fal.VendorTaxCode,
validation.Required,
validation.By(mx.ValidateTaxCode),
validation.Skip, // don't use default code validations
),
validation.Field(&fal.ServiceStationCode,
validation.Required,
Expand Down Expand Up @@ -179,7 +182,8 @@ func (fab *FuelAccountBalance) Calculate() error {
taxtotal := num.MakeAmount(0, FuelAccountTotalsPrecision)
fab.Subtotal = num.MakeAmount(0, FuelAccountTotalsPrecision)

for _, l := range fab.Lines {
for i, l := range fab.Lines {
l.Index = i + 1
// Normalise amounts to the expected precision
l.Quantity = l.Quantity.RescaleUp(FuelAccountPriceMinimumPrecision)
if l.Item != nil {
Expand Down
8 changes: 7 additions & 1 deletion addons/mx/cfdi/fuel_account_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestInvalidComplement(t *testing.T) {
assert.Contains(t, err.Error(), "lines: cannot be blank")
}

func TestInvalidLine(t *testing.T) {
func TestFuelAccountInvalidLine(t *testing.T) {
fab := &cfdi.FuelAccountBalance{Lines: []*cfdi.FuelAccountLine{{}}}

err := fab.Validate()
Expand All @@ -47,6 +47,10 @@ func TestInvalidLine(t *testing.T) {
require.Error(t, err)
assert.Contains(t, err.Error(), "vendor_tax_code: invalid tax identity code")
assert.Contains(t, err.Error(), "total: must be quantity x unit_price")

fab.Lines[0].VendorTaxCode = "K&A010301I16" // with symbols
err = fab.Validate()
assert.NotContains(t, err.Error(), "vendor_tax_code")
}

func TestInvalidItem(t *testing.T) {
Expand Down Expand Up @@ -270,6 +274,7 @@ func TestCalculate(t *testing.T) {
"total": "12.34",
"lines": [
{
"i": 1,
"e_wallet_id": "",
"purchase_date_time": "0000-00-00T00:00:00",
"vendor_tax_code": "",
Expand Down Expand Up @@ -349,6 +354,7 @@ func TestCalculate(t *testing.T) {
"total": "3832.93",
"lines": [
{
"i": 1,
"e_wallet_id": "",
"purchase_date_time": "0000-00-00T00:00:00",
"vendor_tax_code": "",
Expand Down
4 changes: 2 additions & 2 deletions regimes/br/examples/out/invoice-br-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/ca/examples/out/invoice-ca-ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/de/examples/out/invoice-de-de-stnr.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/de/examples/out/invoice-de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/de/examples/out/invoice-de-es-b2b.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/de/examples/out/invoice-de-simplified.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/credit-note-es-es-tbai.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-es-freelance.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-nl-tbai-b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-nl-tbai-exempt.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-simplified.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-usd.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"sum": "2000.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "200.00",
"reason": "Special discount"
"amount": "200.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/fr/examples/out/invoice-fr-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/gb/examples/out/invoice-b2b.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/gr/examples/out/invoice-el-el.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Ειδική Έκπτωση",
"percent": "10%",
"amount": "180.00",
"reason": "Ειδική Έκπτωση"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 2 additions & 2 deletions regimes/gr/examples/out/invoice-islands.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Ειδική Έκπτωση",
"percent": "10%",
"amount": "180.00",
"reason": "Ειδική Έκπτωση"
"amount": "180.00"
}
],
"taxes": [
Expand Down
6 changes: 3 additions & 3 deletions regimes/it/examples/out/flat-rate.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
],
"charges": [
{
"key": "stamp-duty",
"i": 1,
"amount": "2.00",
"reason": "Imposta di bollo"
"key": "stamp-duty",
"reason": "Imposta di bollo",
"amount": "2.00"
}
],
"totals": {
Expand Down
4 changes: 2 additions & 2 deletions regimes/it/examples/out/freelance.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
"sum": "1800.00",
"discounts": [
{
"reason": "Special discount",
"percent": "10%",
"amount": "180.00",
"reason": "Special discount"
"amount": "180.00"
}
],
"taxes": [
Expand Down
4 changes: 3 additions & 1 deletion regimes/mx/examples/out/food-vouchers.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "ea065afce50358819fe68587f573dbad7c0d6ea1626d075b91faa924ebeb07db"
"val": "67be6a62c56ead0addad478296d30fb268c4300fd243be53b14e0f255bdb363a"
}
},
"doc": {
Expand Down Expand Up @@ -107,6 +107,7 @@
"total": "30.52",
"lines": [
{
"i": 1,
"e_wallet_id": "ABC1234",
"issue_date_time": "2022-07-19T10:20:30",
"employee": {
Expand All @@ -118,6 +119,7 @@
"amount": "10.12"
},
{
"i": 2,
"e_wallet_id": "BCD4321",
"issue_date_time": "2022-08-20T11:20:30",
"employee": {
Expand Down
4 changes: 3 additions & 1 deletion regimes/mx/examples/out/fuel-account-balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "d6590300e024e94dd50400b2c016c574222ca1f5259e3da6132e66ebb9d514c9"
"val": "4cc59566b3bb62c784b54b7c938034bb0b5e90d492ba37f76afc975ab8e55384"
}
},
"doc": {
Expand Down Expand Up @@ -107,6 +107,7 @@
"total": "400.00",
"lines": [
{
"i": 1,
"e_wallet_id": "1234",
"purchase_date_time": "2022-07-19T10:20:30",
"vendor_tax_code": "RWT860605OF5",
Expand Down Expand Up @@ -134,6 +135,7 @@
]
},
{
"i": 2,
"e_wallet_id": "1234",
"purchase_date_time": "2022-08-19T10:20:30",
"vendor_tax_code": "DJV320816JT1",
Expand Down
2 changes: 1 addition & 1 deletion regimes/mx/mx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Normalize(doc any) {
case *bill.Invoice:
normalizeInvoice(obj)
case *tax.Identity:
tax.NormalizeIdentity(obj)
NormalizeTaxIdentity(obj)
case *org.Party:
normalizeParty(obj)
}
Expand Down
Loading

0 comments on commit 3e42b81

Please sign in to comment.