Skip to content

Commit

Permalink
Raise validation error if no taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jan 29, 2025
1 parent 53d4a02 commit 566f5c5
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 35 deletions.
19 changes: 13 additions & 6 deletions doc/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ func newImporteTotal(inv *bill.Invoice) string {
totalWithDiscounts := inv.Totals.Total

totalTaxes := num.MakeAmount(0, 2)
for _, category := range inv.Totals.Taxes.Categories {
if !category.Retained {
totalTaxes = totalTaxes.Add(category.Amount)
if inv.Totals.Taxes != nil {
for _, category := range inv.Totals.Taxes.Categories {
if !category.Retained {
totalTaxes = totalTaxes.Add(category.Amount)
}
}
}

Expand All @@ -133,9 +135,11 @@ func newImporteTotal(inv *bill.Invoice) string {

func newRetencionSoportada(inv *bill.Invoice) string {
totalRetention := num.MakeAmount(0, 2)
for _, category := range inv.Totals.Taxes.Categories {
if category.Retained {
totalRetention = totalRetention.Add(category.Amount)
if inv.Totals.Taxes != nil {
for _, category := range inv.Totals.Taxes.Categories {
if category.Retained {
totalRetention = totalRetention.Add(category.Amount)
}
}
}

Expand Down Expand Up @@ -204,6 +208,9 @@ func newFacturasRectificadasSustituidas(inv *bill.Invoice) *FacturasRectificadas
}

func hasSurchargedLines(inv *bill.Invoice) bool {
if inv.Totals == nil || inv.Totals.Taxes == nil {
return false
}
vat := inv.Totals.Taxes.Category(tax.CategoryVAT)
if vat == nil {
return false
Expand Down
3 changes: 3 additions & 0 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func (c *Client) Convert(env *gobl.Envelope) (*doc.TicketBAI, error) {
if inv.Supplier.TaxID.Country != l10n.ES.Tax() {
return nil, ErrValidation.withMessage("only spanish invoices are supported")
}
if inv.Totals == nil || inv.Totals.Taxes == nil {
return nil, ErrValidation.withMessage("missing taxes")
}

zone := zoneFor(inv)
if zone == "" {
Expand Down
12 changes: 9 additions & 3 deletions test/data/credit-note-es-es-tbai.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192237d-4943-72a7-b1d0-51dca3e8bc71",
"dig": {
"alg": "sha256",
"val": "f7165b79e26a6d53e163030b0312e80d15f8af189e0eb51d98864cb06c64e9fc"
"val": "c703a148a9395e3a14882d582618fe6503ab4719007715449c752eaf5cc22831"
}
},
"doc": {
Expand Down Expand Up @@ -86,7 +86,10 @@
"item": {
"name": "Development services",
"price": "90.00",
"unit": "h"
"unit": "h",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1800.00",
"discounts": [
Expand All @@ -110,7 +113,10 @@
"quantity": "1",
"item": {
"name": "Financial service",
"price": "10.00"
"price": "10.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "10.00",
"discounts": [
Expand Down
17 changes: 13 additions & 4 deletions test/data/invoice-es-es-b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192d3c7-2dc5-74cf-b263-5892feb44432",
"dig": {
"alg": "sha256",
"val": "58a808907be339175b8fa53ff5f326f1f074641cfbb653f7f1619763e1f4f2d7"
"val": "57cfc9eb9cc3c8b0013b7ad7ff6fc8b0320d9afbeda923eea05c463bd3cc16cd"
}
},
"doc": {
Expand Down Expand Up @@ -56,7 +56,10 @@
"item": {
"name": "Development services",
"price": "90.00",
"unit": "h"
"unit": "h",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1800.00",
"discounts": [
Expand All @@ -83,7 +86,10 @@
"quantity": "1",
"item": {
"name": "Some merch",
"price": "90.00"
"price": "90.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "90.00",
"taxes": [
Expand All @@ -103,7 +109,10 @@
"quantity": "1",
"item": {
"name": "Some essential needs merch",
"price": "30.00"
"price": "30.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "30.00",
"taxes": [
Expand Down
17 changes: 13 additions & 4 deletions test/data/invoice-es-nl-b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192237d-4965-7c4b-914e-3a62f8e074e5",
"dig": {
"alg": "sha256",
"val": "0ab95209a3a9da3f9e4500a39cd9685f142ff86d42e3d143de14042fe6639749"
"val": "b796c7ee85d32112c3ce7690f4ba5498eaf196ab9df57ea3a2128fe90247b612"
}
},
"doc": {
Expand Down Expand Up @@ -68,7 +68,10 @@
"item": {
"name": "Development services",
"price": "90.00",
"unit": "h"
"unit": "h",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1800.00",
"discounts": [
Expand Down Expand Up @@ -96,7 +99,10 @@
"quantity": "1",
"item": {
"name": "Some merch",
"price": "90.00"
"price": "90.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "90.00",
"taxes": [
Expand All @@ -117,7 +123,10 @@
"quantity": "1",
"item": {
"name": "Some essential needs merch",
"price": "30.00"
"price": "30.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "30.00",
"taxes": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/invoice-es-nl-tbai-b2c-explicit.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192237d-498e-7273-bc95-6a1daf16cb37",
"dig": {
"alg": "sha256",
"val": "bc1cc3c6887e628c94e42d011041522695a73005a3daf4b0f521b9a297e9e97f"
"val": "68b6594f9204664935f572e9fc537e84f680c86a4a325f61ddd646685ffcbde7"
}
},
"doc": {
Expand Down Expand Up @@ -65,7 +65,10 @@
"item": {
"name": "Development services",
"price": "90.00",
"unit": "h"
"unit": "h",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1800.00",
"discounts": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/invoice-es-nl-tbai-exempt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192237d-49c2-79a7-8249-4280119d8ade",
"dig": {
"alg": "sha256",
"val": "0294246ded2b071f8c6eb6011251f3bd254726613b5e7402abcbc2c91e96ecd1"
"val": "f9db4d04b45e555f37068e2d363c153d0a36e29bbdfd828452a78a92491babec"
}
},
"doc": {
Expand Down Expand Up @@ -60,7 +60,10 @@
"item": {
"name": "Development services",
"price": "90.00",
"unit": "h"
"unit": "h",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1800.00",
"discounts": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/invoice-ss.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192fbbc-005b-7eea-8973-210ca4c0ffdc",
"dig": {
"alg": "sha256",
"val": "265465a226476105b9339754dd8e8856033fca217b8b6e89a984295de402b4b6"
"val": "38e8aef5c956bd0ca7ab99d559bdb13174a3f6af82feab70e1e7242bfe10abe7"
}
},
"doc": {
Expand Down Expand Up @@ -74,7 +74,10 @@
"quantity": "10",
"item": {
"name": "Item being purchased",
"price": "100.00"
"price": "100.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1000.00",
"discounts": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/invoice-vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192fd51-6cd8-73f2-a182-8c4d3901d125",
"dig": {
"alg": "sha256",
"val": "a9fcef2ca22b63043a5c66137a39f8ad2be7db01c42ad94f4c5c80ee060c49b0"
"val": "6503a793d90d96cefdfd1652d219a43e44472eb5e8f741d43cf86cb8f984b2ec"
}
},
"doc": {
Expand Down Expand Up @@ -74,7 +74,10 @@
"quantity": "10",
"item": {
"name": "Item being purchased",
"price": "100.00"
"price": "100.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1000.00",
"discounts": [
Expand Down
17 changes: 13 additions & 4 deletions test/data/sample-invoice-export.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192fbd4-5087-708c-9b31-e8f653ef0c52",
"dig": {
"alg": "sha256",
"val": "27db0398b2f300511bfb0401a576876e5061248930ba31fb4d3bd140bddd5a6f"
"val": "963d8171e4ecb8b3c6fa952ce32849d2093fc9f56b9ee35a61741b043bc588d4"
}
},
"doc": {
Expand Down Expand Up @@ -71,7 +71,10 @@
"quantity": "6",
"item": {
"name": "Item being purchased",
"price": "100.00"
"price": "100.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "600.00",
"taxes": [
Expand All @@ -91,7 +94,10 @@
"quantity": "5",
"item": {
"name": "Another item being purchased",
"price": "20.00"
"price": "20.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "100.00",
"taxes": [
Expand All @@ -111,7 +117,10 @@
"quantity": "2",
"item": {
"name": "Service being paid",
"price": "150.00"
"price": "150.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "300.00",
"taxes": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/sample-invoice-supplier2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192fbd4-81b4-75ed-899b-eb4c18a65f1c",
"dig": {
"alg": "sha256",
"val": "177b1a668214b82d634010ca686f671872c4f98865f4c259b88d8025dfbc3aaf"
"val": "cff6f81c8bb31fcf3fbed5429b07a2a9fd36d5ba349592ec83d70f63399be1c5"
}
},
"doc": {
Expand Down Expand Up @@ -74,7 +74,10 @@
"quantity": "15",
"item": {
"name": "Item being purchased",
"price": "90.00"
"price": "90.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1350.00",
"discounts": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/sample-invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192fbd4-a54b-7d7a-be6e-258ea15f17a2",
"dig": {
"alg": "sha256",
"val": "2900e06e5224e2b3c6bf004d036ee3356d3f2a4220fd3deaa80ae871915670b7"
"val": "3d0c71a198b2d0bcf3c07dede6e291c2c552577d7b20c13339fcbc3b77d38ab2"
}
},
"doc": {
Expand Down Expand Up @@ -74,7 +74,10 @@
"quantity": "10",
"item": {
"name": "Item being purchased",
"price": "100.00"
"price": "100.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1000.00",
"discounts": [
Expand Down
7 changes: 5 additions & 2 deletions test/data/sample-invoice2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "0192fbd5-3b54-7735-a8de-2e4f13219f68",
"dig": {
"alg": "sha256",
"val": "61ef29f84ae8f5fe2e0366a0a0dd3582c75dcd46884335619a9d1129343bfa56"
"val": "f598c765c4aa997dff2f37c711415164a459dabd7805d39fcd0321b87bc21cd0"
}
},
"doc": {
Expand Down Expand Up @@ -74,7 +74,10 @@
"quantity": "15",
"item": {
"name": "Item being purchased",
"price": "90.00"
"price": "90.00",
"ext": {
"es-tbai-product": "services"
}
},
"sum": "1350.00",
"discounts": [
Expand Down

0 comments on commit 566f5c5

Please sign in to comment.