polish_invoicer 0.0.25 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +37 -0
- data/.rubocop.yml +7 -5
- data/.rubocop_todo.yml +66 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/doc/invoice.rb +2 -0
- data/doc/proforma.rb +2 -0
- data/lib/polish_invoicer/invoice.rb +21 -5
- data/lib/polish_invoicer/presenter.rb +5 -1
- data/lib/polish_invoicer/validator.rb +27 -9
- data/lib/polish_invoicer/vat.rb +4 -0
- data/lib/polish_invoicer/version.rb +3 -1
- data/lib/polish_invoicer/writer.rb +4 -7
- data/lib/polish_invoicer.rb +2 -0
- data/polish_invoicer.gemspec +10 -5
- data/test/invoice_test.rb +92 -10
- data/test/presenter_test.rb +11 -1
- data/test/test_generator.rb +2 -0
- data/test/test_helper.rb +5 -2
- data/test/validator_test.rb +34 -1
- data/test/vat_test.rb +3 -1
- data/test/writer_test.rb +7 -2
- data/tpl/invoice-en.slim +31 -113
- data/tpl/invoice-es.slim +117 -0
- data/tpl/{invoice.slim → invoice-pl.slim} +1 -1
- data/tpl/invoice-pl_en.slim +199 -0
- data/tpl/proforma-en.slim +27 -83
- data/tpl/proforma-es.slim +104 -0
- data/tpl/proforma-pl_en.slim +160 -0
- metadata +46 -18
- data/.travis.yml +0 -5
- /data/tpl/{proforma.slim → proforma-pl.slim} +0 -0
data/test/invoice_test.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module PolishInvoicer
|
4
6
|
class InvoiceTest < Minitest::Test
|
5
7
|
def test_init
|
6
8
|
i = Invoice.new
|
7
|
-
|
9
|
+
|
10
|
+
assert_kind_of Invoice, i
|
8
11
|
end
|
9
12
|
|
10
13
|
def test_set_available_param
|
11
14
|
i = Invoice.new(number: '1/2014')
|
15
|
+
|
12
16
|
assert_equal '1/2014', i.number
|
13
17
|
end
|
14
18
|
|
@@ -18,86 +22,111 @@ module PolishInvoicer
|
|
18
22
|
|
19
23
|
def test_validation_delegation
|
20
24
|
i = Invoice.new
|
21
|
-
|
25
|
+
|
26
|
+
refute_predicate i, :valid?
|
22
27
|
assert i.errors[:number]
|
23
28
|
i.number = '1/2014'
|
24
29
|
i.valid?
|
30
|
+
|
25
31
|
assert_nil i.errors[:number]
|
26
32
|
end
|
27
33
|
|
28
34
|
def test_net_value
|
29
35
|
i = Invoice.new(price: 123.45, gross_price: false)
|
30
36
|
i.vat = 23
|
37
|
+
|
31
38
|
assert_in_delta 123.45, i.net_value, 0.01
|
32
39
|
|
33
40
|
i.gross_price = true
|
34
41
|
i.vat = 23
|
42
|
+
|
35
43
|
assert_in_delta 100.37, i.net_value, 0.01
|
36
44
|
i.vat = 5.5
|
45
|
+
|
37
46
|
assert_in_delta 117.01, i.net_value, 0.01
|
38
47
|
i.vat = 0
|
48
|
+
|
39
49
|
assert_in_delta 123.45, i.net_value, 0.01
|
40
50
|
i.vat = -1
|
51
|
+
|
41
52
|
assert_in_delta 123.45, i.net_value, 0.01
|
42
53
|
|
43
54
|
i.gross_price = false
|
44
55
|
i.vat = 0
|
56
|
+
|
45
57
|
assert_in_delta 123.45, i.net_value, 0.01
|
46
58
|
i.vat = -1
|
59
|
+
|
47
60
|
assert_in_delta 123.45, i.net_value, 0.01
|
48
61
|
i.vat = 5.5
|
62
|
+
|
49
63
|
assert_in_delta 123.45, i.net_value, 0.01
|
50
64
|
end
|
51
65
|
|
52
66
|
def test_vat_value
|
53
67
|
i = Invoice.new(price: 123.45, gross_price: false)
|
54
68
|
i.vat = 23
|
69
|
+
|
55
70
|
assert_in_delta 28.39, i.vat_value, 0.01
|
56
71
|
i.vat = 5.5
|
72
|
+
|
57
73
|
assert_in_delta 6.79, i.vat_value, 0.01
|
58
74
|
|
59
75
|
i.gross_price = true
|
60
76
|
i.vat = 23
|
77
|
+
|
61
78
|
assert_in_delta 23.08, i.vat_value, 0.01
|
62
79
|
i.vat = 5.5
|
80
|
+
|
63
81
|
assert_in_delta 6.44, i.vat_value, 0.01
|
64
82
|
i.vat = 0
|
65
|
-
|
83
|
+
|
84
|
+
assert_in_delta(0.00, i.vat_value)
|
66
85
|
i.vat = -1
|
67
|
-
|
86
|
+
|
87
|
+
assert_in_delta(0.00, i.vat_value)
|
68
88
|
end
|
69
89
|
|
70
90
|
def test_gross_value
|
71
91
|
i = Invoice.new(price: 123.45, gross_price: false)
|
72
92
|
i.vat = 23
|
93
|
+
|
73
94
|
assert_in_delta 151.84, i.gross_value, 0.01
|
74
95
|
|
75
96
|
i.gross_price = true
|
76
97
|
i.vat = 23
|
98
|
+
|
77
99
|
assert_in_delta 123.45, i.gross_value, 0.01
|
78
100
|
i.vat = 5.5
|
101
|
+
|
79
102
|
assert_in_delta 123.45, i.gross_value, 0.01
|
80
103
|
i.vat = 0
|
104
|
+
|
81
105
|
assert_in_delta 123.45, i.gross_value, 0.01
|
82
106
|
i.vat = -1
|
107
|
+
|
83
108
|
assert_in_delta 123.45, i.gross_value, 0.01
|
84
109
|
|
85
110
|
i.gross_price = false
|
86
111
|
i.vat = 5.5
|
112
|
+
|
87
113
|
assert_in_delta 130.24, i.gross_value, 0.01
|
88
114
|
i.vat = 0
|
115
|
+
|
89
116
|
assert_in_delta 123.45, i.gross_value, 0.01
|
90
117
|
i.vat = -1
|
118
|
+
|
91
119
|
assert_in_delta 123.45, i.gross_value, 0.01
|
92
120
|
end
|
93
121
|
|
94
122
|
def test_defaults
|
95
123
|
i = Invoice.new
|
124
|
+
|
96
125
|
assert i.gross_price
|
97
|
-
|
98
|
-
|
126
|
+
assert_equal 23, i.vat
|
127
|
+
assert_equal 'Przelew', i.payment_type
|
99
128
|
assert i.paid
|
100
|
-
|
129
|
+
refute i.proforma
|
101
130
|
end
|
102
131
|
|
103
132
|
def test_raise_when_save_to_html_and_not_valid
|
@@ -114,7 +143,8 @@ module PolishInvoicer
|
|
114
143
|
i = create_valid_invoice
|
115
144
|
path = '/tmp/test.html'
|
116
145
|
i.save_to_html(path)
|
117
|
-
|
146
|
+
|
147
|
+
assert_path_exists path
|
118
148
|
File.unlink(path)
|
119
149
|
end
|
120
150
|
|
@@ -122,15 +152,17 @@ module PolishInvoicer
|
|
122
152
|
i = create_valid_invoice
|
123
153
|
path = '/tmp/test.pdf'
|
124
154
|
i.save_to_pdf(path)
|
125
|
-
|
155
|
+
|
156
|
+
assert_path_exists path
|
126
157
|
File.unlink(path)
|
127
158
|
end
|
128
159
|
|
129
160
|
def test_to_hash
|
130
161
|
i = Invoice.new(price: 123.45, gross_price: false)
|
131
162
|
h = i.to_hash
|
163
|
+
|
132
164
|
assert h[:paid] # default
|
133
|
-
|
165
|
+
refute h[:gross_price] # params
|
134
166
|
assert_equal '123,45', h[:net_value] # presenter
|
135
167
|
end
|
136
168
|
|
@@ -159,6 +191,7 @@ module PolishInvoicer
|
|
159
191
|
|
160
192
|
def test_gross_and_net_price
|
161
193
|
gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false)
|
194
|
+
|
162
195
|
assert_equal 100, gross_invoice.net_value
|
163
196
|
assert_equal 23, gross_invoice.vat_value
|
164
197
|
assert_equal 123, gross_invoice.gross_value
|
@@ -167,6 +200,7 @@ module PolishInvoicer
|
|
167
200
|
assert_equal 63, gross_invoice.to_pay_value
|
168
201
|
|
169
202
|
net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false)
|
203
|
+
|
170
204
|
assert_equal 100, net_invoice.net_value
|
171
205
|
assert_equal 23, net_invoice.vat_value
|
172
206
|
assert_equal 123, net_invoice.gross_value
|
@@ -177,6 +211,7 @@ module PolishInvoicer
|
|
177
211
|
|
178
212
|
def test_reverse_charge
|
179
213
|
gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false, reverse_charge: true)
|
214
|
+
|
180
215
|
assert_equal 100, gross_invoice.net_value
|
181
216
|
assert_equal 23, gross_invoice.vat_value
|
182
217
|
assert_equal 123, gross_invoice.gross_value
|
@@ -185,6 +220,7 @@ module PolishInvoicer
|
|
185
220
|
assert_equal 40, gross_invoice.to_pay_value
|
186
221
|
|
187
222
|
net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false, reverse_charge: true)
|
223
|
+
|
188
224
|
assert_equal 100, net_invoice.net_value
|
189
225
|
assert_equal 23, net_invoice.vat_value
|
190
226
|
assert_equal 123, net_invoice.gross_value
|
@@ -192,5 +228,51 @@ module PolishInvoicer
|
|
192
228
|
assert_equal 60, net_invoice.paid_value
|
193
229
|
assert_equal 40, net_invoice.to_pay_value
|
194
230
|
end
|
231
|
+
|
232
|
+
def test_template_lang
|
233
|
+
i = Invoice.new
|
234
|
+
|
235
|
+
assert_equal 'pl', i.template_lang
|
236
|
+
i.foreign_buyer = true
|
237
|
+
|
238
|
+
assert_equal 'pl_en', i.template_lang
|
239
|
+
i.lang = 'en'
|
240
|
+
|
241
|
+
assert_equal 'en', i.template_lang
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_template_file
|
245
|
+
i = Invoice.new(proforma: true)
|
246
|
+
|
247
|
+
assert_equal 'proforma-pl.slim', i.template_file
|
248
|
+
i.foreign_buyer = true
|
249
|
+
|
250
|
+
assert_equal 'proforma-pl_en.slim', i.template_file
|
251
|
+
i.lang = 'en'
|
252
|
+
|
253
|
+
assert_equal 'proforma-en.slim', i.template_file
|
254
|
+
i.lang = 'pl'
|
255
|
+
|
256
|
+
assert_equal 'proforma-pl.slim', i.template_file
|
257
|
+
i.lang = 'pl_en'
|
258
|
+
|
259
|
+
assert_equal 'proforma-pl_en.slim', i.template_file
|
260
|
+
|
261
|
+
i = Invoice.new
|
262
|
+
|
263
|
+
assert_equal 'invoice-pl.slim', i.template_file
|
264
|
+
i.foreign_buyer = true
|
265
|
+
|
266
|
+
assert_equal 'invoice-pl_en.slim', i.template_file
|
267
|
+
i.lang = 'en'
|
268
|
+
|
269
|
+
assert_equal 'invoice-en.slim', i.template_file
|
270
|
+
i.lang = 'pl'
|
271
|
+
|
272
|
+
assert_equal 'invoice-pl.slim', i.template_file
|
273
|
+
i.lang = 'pl_en'
|
274
|
+
|
275
|
+
assert_equal 'invoice-pl_en.slim', i.template_file
|
276
|
+
end
|
195
277
|
end
|
196
278
|
end
|
data/test/presenter_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module PolishInvoicer
|
@@ -13,6 +15,7 @@ module PolishInvoicer
|
|
13
15
|
@invoice.create_date = Date.parse('2014-01-15')
|
14
16
|
@invoice.payment_date = Date.parse('2014-01-30')
|
15
17
|
data = Presenter.new(@invoice).data
|
18
|
+
|
16
19
|
assert_equal '01.01.2014', data[:trade_date]
|
17
20
|
assert_equal '15.01.2014', data[:create_date]
|
18
21
|
assert_equal '30.01.2014', data[:payment_date]
|
@@ -23,6 +26,7 @@ module PolishInvoicer
|
|
23
26
|
@invoice.vat_value = 23.9876
|
24
27
|
@invoice.gross_value = 456.3378
|
25
28
|
data = Presenter.new(@invoice).data
|
29
|
+
|
26
30
|
assert_equal '123,46', data[:net_value]
|
27
31
|
assert_equal '23,99', data[:vat_value]
|
28
32
|
assert_equal '456,34', data[:gross_value]
|
@@ -31,24 +35,30 @@ module PolishInvoicer
|
|
31
35
|
def test_format_comments
|
32
36
|
@invoice.comments = nil
|
33
37
|
data = Presenter.new(@invoice).data
|
34
|
-
|
38
|
+
|
39
|
+
assert_empty data[:comments]
|
35
40
|
@invoice.comments = 'Test'
|
36
41
|
data = Presenter.new(@invoice).data
|
42
|
+
|
37
43
|
assert_equal ['Test'], data[:comments]
|
38
44
|
@invoice.comments = %w[A B]
|
39
45
|
data = Presenter.new(@invoice).data
|
46
|
+
|
40
47
|
assert_equal %w[A B], data[:comments]
|
41
48
|
end
|
42
49
|
|
43
50
|
def test_vat
|
44
51
|
@invoice.vat = 23
|
45
52
|
data = Presenter.new(@invoice).data
|
53
|
+
|
46
54
|
assert_equal '23%', data[:vat]
|
47
55
|
@invoice.vat = 0
|
48
56
|
data = Presenter.new(@invoice).data
|
57
|
+
|
49
58
|
assert_equal '0%', data[:vat]
|
50
59
|
@invoice.vat = -1
|
51
60
|
data = Presenter.new(@invoice).data
|
61
|
+
|
52
62
|
assert_equal 'zw.', data[:vat]
|
53
63
|
end
|
54
64
|
end
|
data/test/test_generator.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'simplecov'
|
2
4
|
SimpleCov.start do
|
3
5
|
add_filter '/test/'
|
4
6
|
end
|
5
7
|
|
6
|
-
$LOAD_PATH.unshift File.expand_path('
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
7
9
|
require 'polish_invoicer'
|
8
10
|
require 'minitest/autorun'
|
9
11
|
|
@@ -14,6 +16,7 @@ def create_valid_invoice
|
|
14
16
|
seller_nip: '123-123-22-33', buyer_nip: '554-333-22-11',
|
15
17
|
item_name: 'Title', price: 123.45, payment_date: Date.today
|
16
18
|
)
|
17
|
-
|
19
|
+
|
20
|
+
assert_predicate invoice, :valid?
|
18
21
|
invoice
|
19
22
|
end
|
data/test/validator_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module PolishInvoicer
|
@@ -111,10 +113,12 @@ module PolishInvoicer
|
|
111
113
|
@invoice.proforma = true
|
112
114
|
v = Validator.new(@invoice)
|
113
115
|
v.valid?
|
116
|
+
|
114
117
|
assert v.errors[:paid]
|
115
118
|
@invoice.paid = false
|
116
119
|
v = Validator.new(@invoice)
|
117
120
|
v.valid?
|
121
|
+
|
118
122
|
assert_nil v.errors[:paid]
|
119
123
|
end
|
120
124
|
|
@@ -129,14 +133,17 @@ module PolishInvoicer
|
|
129
133
|
@invoice.vat = 23
|
130
134
|
v = Validator.new(@invoice)
|
131
135
|
v.valid?
|
136
|
+
|
132
137
|
assert_nil v.errors[:no_vat_reason]
|
133
138
|
@invoice.vat = -1
|
134
139
|
v = Validator.new(@invoice)
|
135
140
|
v.valid?
|
141
|
+
|
136
142
|
assert v.errors[:no_vat_reason]
|
137
143
|
@invoice.no_vat_reason = 'reason'
|
138
144
|
v = Validator.new(@invoice)
|
139
145
|
v.valid?
|
146
|
+
|
140
147
|
assert_nil v.errors[:no_vat_reason]
|
141
148
|
end
|
142
149
|
|
@@ -145,10 +152,12 @@ module PolishInvoicer
|
|
145
152
|
@invoice.payment_date = Date.parse('2018-04-01')
|
146
153
|
v = Validator.new(@invoice)
|
147
154
|
v.valid?
|
155
|
+
|
148
156
|
assert v.errors[:payment_date]
|
149
157
|
@invoice.payment_date = Date.parse('2018-04-17')
|
150
158
|
v = Validator.new(@invoice)
|
151
159
|
v.valid?
|
160
|
+
|
152
161
|
assert_nil v.errors[:payment_date]
|
153
162
|
end
|
154
163
|
|
@@ -156,14 +165,17 @@ module PolishInvoicer
|
|
156
165
|
@invoice.currency = nil
|
157
166
|
v = Validator.new(@invoice)
|
158
167
|
v.valid?
|
168
|
+
|
159
169
|
assert v.errors[:currency]
|
160
170
|
@invoice.currency = 'XYZ'
|
161
171
|
v = Validator.new(@invoice)
|
162
172
|
v.valid?
|
173
|
+
|
163
174
|
assert v.errors[:currency]
|
164
175
|
@invoice.currency = 'EUR'
|
165
176
|
v = Validator.new(@invoice)
|
166
177
|
v.valid?
|
178
|
+
|
167
179
|
refute v.errors[:currency]
|
168
180
|
end
|
169
181
|
|
@@ -171,19 +183,39 @@ module PolishInvoicer
|
|
171
183
|
@invoice.exchange_rate = nil
|
172
184
|
v = Validator.new(@invoice)
|
173
185
|
v.valid?
|
186
|
+
|
174
187
|
assert v.errors[:exchange_rate]
|
175
|
-
@invoice.exchange_rate = 4
|
188
|
+
@invoice.exchange_rate = 4.1234
|
176
189
|
v = Validator.new(@invoice)
|
177
190
|
v.valid?
|
191
|
+
|
178
192
|
refute v.errors[:exchange_rate]
|
179
193
|
end
|
180
194
|
|
195
|
+
def test_lang
|
196
|
+
v = Validator.new(@invoice)
|
197
|
+
v.valid?
|
198
|
+
|
199
|
+
refute v.errors[:lang]
|
200
|
+
@invoice.lang = 'xx'
|
201
|
+
v = Validator.new(@invoice)
|
202
|
+
v.valid?
|
203
|
+
|
204
|
+
assert v.errors[:lang]
|
205
|
+
@invoice.lang = 'en'
|
206
|
+
v = Validator.new(@invoice)
|
207
|
+
v.valid?
|
208
|
+
|
209
|
+
refute v.errors[:lang]
|
210
|
+
end
|
211
|
+
|
181
212
|
private
|
182
213
|
|
183
214
|
def check_error(field, value = nil)
|
184
215
|
@invoice.send("#{field}=", value)
|
185
216
|
v = Validator.new(@invoice)
|
186
217
|
v.valid?
|
218
|
+
|
187
219
|
assert v.errors[field]
|
188
220
|
end
|
189
221
|
|
@@ -191,6 +223,7 @@ module PolishInvoicer
|
|
191
223
|
@invoice.send("#{field}=", value)
|
192
224
|
v = Validator.new(@invoice)
|
193
225
|
v.valid?
|
226
|
+
|
194
227
|
assert_nil v.errors[field]
|
195
228
|
end
|
196
229
|
end
|
data/test/vat_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module PolishInvoicer
|
@@ -31,7 +33,7 @@ module PolishInvoicer
|
|
31
33
|
|
32
34
|
def test_to_i
|
33
35
|
assert_equal 0, Vat.to_i(-1)
|
34
|
-
|
36
|
+
assert_in_delta(5.5, Vat.to_i(5.5))
|
35
37
|
assert_equal 20, Vat.to_i(20)
|
36
38
|
end
|
37
39
|
end
|
data/test/writer_test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module PolishInvoicer
|
@@ -7,7 +9,8 @@ module PolishInvoicer
|
|
7
9
|
writer = Writer.new(invoice)
|
8
10
|
path = '/tmp/test.html'
|
9
11
|
writer.save_to_html(path)
|
10
|
-
|
12
|
+
|
13
|
+
assert_path_exists path
|
11
14
|
File.unlink(path)
|
12
15
|
end
|
13
16
|
|
@@ -16,7 +19,8 @@ module PolishInvoicer
|
|
16
19
|
writer = Writer.new(invoice)
|
17
20
|
path = '/tmp/test.pdf'
|
18
21
|
writer.save_to_pdf(path)
|
19
|
-
|
22
|
+
|
23
|
+
assert_path_exists path
|
20
24
|
File.unlink(path)
|
21
25
|
end
|
22
26
|
|
@@ -26,6 +30,7 @@ module PolishInvoicer
|
|
26
30
|
invoice.logger = 'FakeLogger'
|
27
31
|
invoice.wkhtmltopdf_command = 'wkhtmltopdf_fake_command'
|
28
32
|
writer = Writer.new(invoice)
|
33
|
+
|
29
34
|
assert_equal 'tpl.slim', writer.template_path
|
30
35
|
assert_equal 'FakeLogger', writer.logger
|
31
36
|
assert_equal 'wkhtmltopdf_fake_command', writer.wkhtmltopdf_command
|