Skip to content

Commit

Permalink
Add fuel account balance complement to MX regime
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Sep 29, 2023
1 parent 5de93db commit 4e8c219
Show file tree
Hide file tree
Showing 6 changed files with 540 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bill/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (inv *Invoice) ValidateWithContext(ctx context.Context) error {

validation.Field(&inv.Notes),
validation.Field(&inv.Meta),

validation.Field(&inv.Complements, validation.Each()),
)
if err == nil {
err = r.ValidateObject(inv)
Expand Down Expand Up @@ -466,6 +468,20 @@ func (inv *Invoice) calculate(r *tax.Regime, tID *tax.Identity) error {

t.round(zero)

// Complements
if err := calculateComplements(r, inv.Complements); err != nil {
return validation.Errors{"complements": err}
}

return nil
}

func calculateComplements(r *tax.Regime, comps []*schema.Object) error {

Check failure on line 479 in bill/invoice.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`calculateComplements` - `r` is unused (unparam)
for _, c := range comps {
if err := c.Calculate(); err != nil {
return err
}
}
return nil
}

Expand Down
76 changes: 76 additions & 0 deletions regimes/mx/examples/fuel-account-balance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
$schema: "https://gobl.org/draft-0/bill/invoice"
issue_date: "2023-07-10"
series: "TEST"
code: "00002"
supplier:
name: "ESCUELA KEMPER URGATE"
ext:
mx-cfdi-fiscal-regime: "601"
tax_id:
country: "MX"
code: "EKU9003173C9"
zone: "21000"
customer:
name: "UNIVERSIDAD ROBOTICA ESPAÑOLA"
ext:
mx-cfdi-fiscal-regime: "601"
mx-cfdi-use: "G01"
tax_id:
country: "MX"
code: "URE180429TM6"
zone: "86991"
lines:
- quantity: "1"
item:
name: "Comisión servicio de monedero electrónico"
price: "10.00"
ext:
mx-cfdi-prod-serv: "84141602"
taxes:
- cat: "VAT"
rate: "standard"
payment:
terms:
notes: "Condiciones de pago"
instructions:
key: "online+wallet"
complements:
- $schema: "https://gobl.org/draft-0/regimes/mx/fuel-account-balance"
account_number: "0123456789"
lines:
- e_wallet_id: "1234"
purchase_date_time: "2022-07-19T10:20:30"
vendor_tax_code: "RWT860605OF5"
service_station_code: "8171650"
quantity: "9.6613"
unit: "l"
fuel_type: "3"
fuel_name: "Diesel"
unit_price: "12.7428"
purchase_code: "2794668"
total: "123.11"
taxes:
- code: "IVA"
rate: "0.16"
amount: "19.70"
- code: "IEPS"
rate: "5.9195"
amount: "57.19"
- e_wallet_id: "1234"
purchase_date_time: "2022-08-19T10:20:30"
vendor_tax_code: "DJV320816JT1"
service_station_code: "8171667"
quantity: "9.68"
fuel_type: "1"
fuel_name: "Gasolina Magna"
unit_price: "12.709"
purchase_code: "2794669"
total: "123.02"
taxes:
- code: "IVA"
rate: "0.16"
amount: "19.68"
- code: "IEPS"
rate: "5.9195"
amount: "57.30"

155 changes: 155 additions & 0 deletions regimes/mx/examples/out/fuel-account-balance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"$schema": "https://gobl.org/draft-0/envelope",
"head": {
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "c0a43b719859e1f656b6a3bf6cc500703f1536240a110522a7f3f7fbeb566ef4"
},
"draft": true
},
"doc": {
"$schema": "https://gobl.org/draft-0/bill/invoice",
"type": "standard",
"series": "TEST",
"code": "00002",
"issue_date": "2023-07-10",
"currency": "MXN",
"supplier": {
"name": "ESCUELA KEMPER URGATE",
"tax_id": {
"country": "MX",
"zone": "21000",
"code": "EKU9003173C9"
},
"ext": {
"mx-cfdi-fiscal-regime": "601"
}
},
"customer": {
"name": "UNIVERSIDAD ROBOTICA ESPAÑOLA",
"tax_id": {
"country": "MX",
"zone": "86991",
"code": "URE180429TM6"
},
"ext": {
"mx-cfdi-fiscal-regime": "601",
"mx-cfdi-use": "G01"
}
},
"lines": [
{
"i": 1,
"quantity": "1",
"item": {
"name": "Comisión servicio de monedero electrónico",
"price": "10.00",
"ext": {
"mx-cfdi-prod-serv": "84141602"
}
},
"sum": "10.00",
"taxes": [
{
"cat": "VAT",
"rate": "standard",
"percent": "16.0%"
}
],
"total": "10.00"
}
],
"payment": {
"terms": {
"notes": "Condiciones de pago"
},
"instructions": {
"key": "online+wallet"
}
},
"totals": {
"sum": "10.00",
"total": "10.00",
"taxes": {
"categories": [
{
"code": "VAT",
"rates": [
{
"key": "standard",
"base": "10.00",
"percent": "16.0%",
"amount": "1.60"
}
],
"amount": "1.60"
}
],
"sum": "1.60"
},
"tax": "1.60",
"total_with_tax": "11.60",
"payable": "11.60"
},
"complements": [
{
"$schema": "https://gobl.org/draft-0/regimes/mx/fuel-account-balance",
"account_number": "0123456789",
"subtotal": "246.13",
"total": "400.00",
"lines": [
{
"e_wallet_id": "1234",
"purchase_date_time": "2022-07-19T10:20:30",
"vendor_tax_code": "RWT860605OF5",
"service_station_code": "8171650",
"quantity": "9.661",
"fuel_type": "3",
"unit": "l",
"fuel_name": "Diesel",
"unit_price": "12.743",
"purchase_code": "2794668",
"total": "123.11",
"taxes": [
{
"code": "IVA",
"rate": "0.160000",
"amount": "19.70"
},
{
"code": "IEPS",
"rate": "5.919500",
"amount": "57.19"
}
]
},
{
"e_wallet_id": "1234",
"purchase_date_time": "2022-08-19T10:20:30",
"vendor_tax_code": "DJV320816JT1",
"service_station_code": "8171667",
"quantity": "9.680",
"fuel_type": "1",
"fuel_name": "Gasolina Magna",
"unit_price": "12.709",
"purchase_code": "2794669",
"total": "123.02",
"taxes": [
{
"code": "IVA",
"rate": "0.160000",
"amount": "19.68"
},
{
"code": "IEPS",
"rate": "5.919500",
"amount": "57.30"
}
]
}
]
}
]
}
}
Loading

0 comments on commit 4e8c219

Please sign in to comment.