Skip to content

Commit

Permalink
Unsupport charges and discounts in NFSe addon
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Oct 25, 2024
1 parent 2b6842c commit 177eb69
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
19 changes: 19 additions & 0 deletions addons/br/nfse/invoices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nfse

import (
"github.com/invopop/gobl/bill"
"github.com/invopop/validation"
)

func validateInvoice(inv *bill.Invoice) error {
return validation.ValidateStruct(inv,
validation.Field(&inv.Charges,
validation.Empty.Error("not supported by nfse"),
validation.Skip,
),
validation.Field(&inv.Discounts,
validation.Empty.Error("not supported by nfse"),
validation.Skip,
),
)
}
60 changes: 60 additions & 0 deletions addons/br/nfse/invoices_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package nfse_test

import (
"testing"

"github.com/invopop/gobl/addons/br/nfse"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
)

func TestInvoicesValidation(t *testing.T) {
tests := []struct {
name string
inv *bill.Invoice
err string
}{
{
name: "valid invoice",
inv: &bill.Invoice{},
},
{
name: "charges present",
inv: &bill.Invoice{
Charges: []*bill.Charge{
{
Amount: num.MakeAmount(100, 2),
},
},
},
err: "charges: not supported by nfse.",
},
{
name: "discounts present",
inv: &bill.Invoice{
Discounts: []*bill.Discount{
{
Amount: num.MakeAmount(100, 2),
},
},
},
err: "discounts: not supported by nfse.",
},
}

addon := tax.AddonForKey(nfse.V1)
for _, ts := range tests {
t.Run(ts.name, func(t *testing.T) {
err := addon.Validator(ts.inv)
if ts.err == "" {
assert.NoError(t, err)
} else {
if assert.Error(t, err) {
assert.Contains(t, err.Error(), ts.err)
}
}
})
}
}
2 changes: 2 additions & 0 deletions addons/br/nfse/nfse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func newAddon() *tax.AddonDef {

func validate(doc any) error {
switch obj := doc.(type) {
case *bill.Invoice:
return validateInvoice(obj)
case *bill.Line:
return validateLine(obj)
case *org.Item:
Expand Down

0 comments on commit 177eb69

Please sign in to comment.