Skip to content

Commit

Permalink
Cover Preceding
Browse files Browse the repository at this point in the history
  • Loading branch information
apardods committed Nov 26, 2024
1 parent 496b504 commit d0055be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions addons/es/verifactu/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func validateInvoice(inv *bill.Invoice) error {
inv.Type.In(es.InvoiceCorrectionTypes...),
validation.Required,
),
validation.By(validateInvoicePreceding),
validation.Each(
validation.By(validateInvoicePreceding),
),
validation.Skip,
),
validation.Field(&inv.Tax,
Expand Down Expand Up @@ -65,8 +67,8 @@ func validateInvoiceTax(val any) error {
}

func validateInvoiceCustomer(val any) error {
obj, _ := val.(*org.Party)
if obj == nil {
obj, ok := val.(*org.Party)
if !ok || obj == nil {
return nil
}
// Customers must have a tax ID to at least set the country,
Expand All @@ -86,7 +88,7 @@ func validateInvoiceCustomer(val any) error {

func validateInvoicePreceding(val any) error {
p, ok := val.(*org.DocumentRef)
if !ok {
if !ok || p == nil {
return nil
}

Check warning on line 93 in addons/es/verifactu/invoice.go

View check run for this annotation

Codecov / codecov/patch

addons/es/verifactu/invoice.go#L92-L93

Added lines #L92 - L93 were not covered by tests
return validation.ValidateStruct(p,
Expand All @@ -97,8 +99,8 @@ func validateInvoicePreceding(val any) error {
}

func validateInvoiceLine(value any) error {
obj, _ := value.(*bill.Line)
if obj == nil {
obj, ok := value.(*bill.Line)
if !ok || obj == nil {
return nil
}

Check warning on line 105 in addons/es/verifactu/invoice.go

View check run for this annotation

Codecov / codecov/patch

addons/es/verifactu/invoice.go#L104-L105

Added lines #L104 - L105 were not covered by tests
return validation.ValidateStruct(obj,
Expand Down
11 changes: 11 additions & 0 deletions addons/es/verifactu/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ func TestInvoiceValidation(t *testing.T) {
assertValidationError(t, inv, "preceding: cannot be blank")
})

t.Run("correction invoice preceding requires issue date", func(t *testing.T) {
inv := testInvoiceStandard(t)
inv.Type = bill.InvoiceTypeCreditNote
inv.Preceding = []*org.DocumentRef{
{
Code: "123",
},
}
assertValidationError(t, inv, "preceding: (0: (issue_date: cannot be blank.).)")
})

t.Run("correction invoice with preceding", func(t *testing.T) {
inv := testInvoiceStandard(t)
inv.Type = bill.InvoiceTypeCreditNote
Expand Down

0 comments on commit d0055be

Please sign in to comment.