-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlines_test.go
More file actions
97 lines (81 loc) · 3.27 KB
/
Copy pathlines_test.go
File metadata and controls
97 lines (81 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package convert_test
import (
"testing"
"time"
"github.com/invopop/gobl.ticketbai/convert"
"github.com/invopop/gobl.ticketbai/test"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLines(t *testing.T) {
ts, err := time.Parse(time.RFC3339, "2022-02-01T04:00:00Z")
require.NoError(t, err)
role := convert.IssuerRoleThirdParty
t.Run("should show line info", func(t *testing.T) {
goblInvoice := test.LoadInvoice("sample-invoice.json")
goblInvoice.Lines = []*bill.Line{{
Index: 1,
Quantity: num.MakeAmount(100, 0),
Item: &org.Item{Name: "A", Price: num.NewAmount(10, 0)},
Taxes: tax.Set{&tax.Combo{Category: tax.CategoryVAT, Rate: "standard"}},
}}
_ = goblInvoice.Calculate()
invoice, _ := convert.NewTicketBAI(goblInvoice, ts, role, convert.ZoneBI)
lines := invoice.Factura.DatosFactura.DetallesFactura.IDDetalleFactura
assert.Equal(t, 1, len(lines))
assert.Equal(t, "A", lines[0].DescripcionDetalle)
assert.Equal(t, "100", lines[0].Cantidad)
assert.Equal(t, "10.00", lines[0].ImporteUnitario)
assert.Equal(t, "1210.00", lines[0].ImporteTotal)
})
t.Run("should show line discount", func(t *testing.T) {
goblInvoice := test.LoadInvoice("sample-invoice.json")
goblInvoice.Lines = []*bill.Line{{
Index: 1,
Quantity: num.MakeAmount(100, 0),
Item: &org.Item{Name: "A", Price: num.NewAmount(11, 0)},
Discounts: []*bill.LineDiscount{DiscountOf(100)},
Taxes: tax.Set{&tax.Combo{Category: tax.CategoryVAT, Rate: "standard"}},
}}
_ = goblInvoice.Calculate()
invoice, _ := convert.NewTicketBAI(goblInvoice, ts, role, convert.ZoneBI)
line := invoice.Factura.DatosFactura.DetallesFactura.IDDetalleFactura[0]
assert.Equal(t, "100.00", line.Descuento)
assert.Equal(t, "1210.00", line.ImporteTotal)
})
t.Run("should subtract taxes if included in prices per unit", func(t *testing.T) {
inv := test.LoadInvoice("sample-invoice.json")
inv.Tax = &bill.Tax{PricesInclude: "VAT"}
inv.Lines = []*bill.Line{{
Index: 1,
Quantity: num.MakeAmount(10, 0),
Item: &org.Item{Name: "A", Price: num.NewAmount(121, 0)},
Taxes: tax.Set{&tax.Combo{Category: tax.CategoryVAT, Rate: "standard"}},
}}
require.NoError(t, inv.Calculate())
require.NoError(t, inv.RemoveIncludedTaxes())
out, _ := convert.NewTicketBAI(inv, ts, role, convert.ZoneBI)
line := out.Factura.DatosFactura.DetallesFactura.IDDetalleFactura[0]
assert.Equal(t, "100.00", line.ImporteUnitario)
assert.Equal(t, "1210.00", line.ImporteTotal)
})
t.Run("should return error if more than 1000 lines included and not Vizcaya", func(t *testing.T) {
inv := test.LoadInvoice("sample-invoice.json")
inv.Lines = []*bill.Line{}
for i := 1; i <= 1001; i++ {
inv.Lines = append(inv.Lines, &bill.Line{
Index: 1,
Quantity: num.MakeAmount(100, 0),
Item: &org.Item{Name: "A", Price: num.NewAmount(10, 0)},
Taxes: tax.Set{&tax.Combo{Category: tax.CategoryVAT, Rate: tax.RateGeneral}},
})
}
require.NoError(t, inv.Calculate())
_, err := convert.NewTicketBAI(inv, ts, role, convert.ZoneSS)
assert.ErrorContains(t, err, "line count over limit (1000) for tax locality")
})
}