Skip to content

Commit

Permalink
Avoid requiring the tax to be present
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Jan 30, 2025
1 parent a2443d1 commit 278986c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions addons/pt/saft/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var (
func validateInvoice(inv *bill.Invoice) error {
return validation.ValidateStruct(inv,
validation.Field(&inv.Tax,
validation.Required,
validation.By(validateTax),
validation.Skip,
),
Expand Down Expand Up @@ -60,7 +59,7 @@ func validateInvoice(inv *bill.Invoice) error {
func validateTax(val any) error {
t, _ := val.(*bill.Tax)
if t == nil {
return nil
t = new(bill.Tax)
}

return validation.ValidateStruct(t,
Expand Down
2 changes: 1 addition & 1 deletion addons/pt/saft/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestInvoiceValidation(t *testing.T) {
inv := validInvoice()

inv.Tax = nil
assert.ErrorContains(t, addon.Validator(inv), "tax: cannot be blank")
assert.ErrorContains(t, addon.Validator(inv), "tax: (ext: (pt-saft-invoice-type: required")

inv.Tax = new(bill.Tax)
assert.ErrorContains(t, addon.Validator(inv), "tax: (ext: (pt-saft-invoice-type: required")
Expand Down

0 comments on commit 278986c

Please sign in to comment.