diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e98a770..b466b2a70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - `cbc.CodeMap`: added `Lookup` method that returns the code matching a given key, falling back hierarchically to less specific keys. - `pay`: added `MeansKeyCredit` and `MeansKeyDebit` qualifiers, enabling the `card+credit` and `card+debit` payment means. Adapted all addons mapping payment means to extensions to use the two new qualified means. - `es-tbai-v1`: added `es-tbai-bi-activity` extension for the Bizkaia activity code (epĂ­grafe) required for individual suppliers. +- `pt-saft-v1`: added rule to check that advance payment amounts on invoices are no less than 0 as required by the SAF-T spec. ## [v0.402.0] - 2026-04-30 diff --git a/addons/pt/saft/invoices.go b/addons/pt/saft/invoices.go index 9c49bc034..884c6e00c 100644 --- a/addons/pt/saft/invoices.go +++ b/addons/pt/saft/invoices.go @@ -137,6 +137,9 @@ func billInvoiceRules() *rules.Set { rules.Field("date", rules.Assert("08", "cannot be blank", is.Present), ), + rules.Field("amount", + rules.Assert("16", "must be no less than 0", num.ZeroOrPositive), + ), ), ), ), diff --git a/addons/pt/saft/invoices_test.go b/addons/pt/saft/invoices_test.go index d64db1824..bc868d2e7 100644 --- a/addons/pt/saft/invoices_test.go +++ b/addons/pt/saft/invoices_test.go @@ -412,6 +412,20 @@ func TestInvoicePaymentValidation(t *testing.T) { assert.ErrorContains(t, rules.Validate(inv), "cannot be blank") }) + t.Run("advance with negative amount", func(t *testing.T) { + d := cal.NewDate(2024, 1, 1) + inv := calculatedInvoice(t) + inv.Payment = &bill.PaymentDetails{ + Advances: []*pay.Record{ + { + Date: d, + Amount: num.MakeAmount(-50, 0), + }, + }, + } + assert.ErrorContains(t, rules.Validate(inv), "must be no less than 0") + }) + t.Run("nil advance", func(t *testing.T) { inv := calculatedInvoice(t) inv.Payment = &bill.PaymentDetails{ diff --git a/data/rules/pt-saft.json b/data/rules/pt-saft.json index e90202215..ca2743f83 100644 --- a/data/rules/pt-saft.json +++ b/data/rules/pt-saft.json @@ -92,6 +92,16 @@ "tests": "present" } ] + }, + { + "field": "amount", + "assert": [ + { + "id": "GOBL-PT-SAFT-BILL-INVOICE-16", + "desc": "must be no less than 0", + "tests": "min 0" + } + ] } ] }