Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use Test::More tests => 8; |
3 |
use Test::MockModule; |
4 |
|
5 |
use C4::Acquisition; |
6 |
use C4::Bookseller; |
7 |
use C4::Context; |
8 |
|
9 |
use Koha::Number::Price; |
10 |
|
11 |
use t::lib::Mocks; |
12 |
|
13 |
t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' ); |
14 |
|
15 |
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller'); |
16 |
|
17 |
my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 ); |
18 |
my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 ); |
19 |
my $today; |
20 |
|
21 |
for my $currency_format ( qw( US FR ) ) { |
22 |
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); |
23 |
subtest 'Configuration 1: 0 0' => sub { |
24 |
plan tests => 7; |
25 |
$bookseller_module->mock( |
26 |
'fetch', |
27 |
sub { |
28 |
return { listincgst => 0, invoiceincgst => 0 }; |
29 |
} |
30 |
); |
31 |
|
32 |
my $biblionumber_0_0 = 42; |
33 |
|
34 |
my $order_0_0 = { |
35 |
biblionumber => $biblionumber_0_0, |
36 |
quantity => 2, |
37 |
listprice => 82.000000, |
38 |
unitprice => 73.80000, |
39 |
quantityreceived => 2, |
40 |
basketno => $basketno_0_0, |
41 |
invoiceid => $invoiceid_0_0, |
42 |
rrp => 82.00, |
43 |
ecost => 73.80, |
44 |
gstrate => 0.0500, |
45 |
discount => 10.0000, |
46 |
datereceived => $today |
47 |
}; |
48 |
$order_0_0 = C4::Acquisition::populate_order_with_prices( |
49 |
{ |
50 |
order => $order_0_0, |
51 |
booksellerid => 'just_something', |
52 |
ordering => 1, |
53 |
} |
54 |
); |
55 |
|
56 |
# Note that this configuration is correct \o/ |
57 |
compare( |
58 |
{ |
59 |
got => $order_0_0->{rrpgsti}, |
60 |
expected => 86.10, |
61 |
conf => '0 0', |
62 |
field => 'rrpgsti' |
63 |
} |
64 |
); |
65 |
compare( |
66 |
{ |
67 |
got => $order_0_0->{rrpgste}, |
68 |
expected => 82.00, |
69 |
conf => '0 0', |
70 |
field => 'rrpgsti' |
71 |
} |
72 |
); |
73 |
compare( |
74 |
{ |
75 |
got => $order_0_0->{ecostgsti}, |
76 |
expected => 77.49, |
77 |
conf => '0 0', |
78 |
field => 'ecostgsti' |
79 |
} |
80 |
); |
81 |
compare( |
82 |
{ |
83 |
got => $order_0_0->{ecostgste}, |
84 |
expected => 73.80, |
85 |
conf => '0 0', |
86 |
field => 'ecostgste' |
87 |
} |
88 |
); |
89 |
compare( |
90 |
{ |
91 |
got => $order_0_0->{gstvalue}, |
92 |
expected => 7.38, |
93 |
conf => '0 0', |
94 |
field => 'gstvalue' |
95 |
} |
96 |
); |
97 |
compare( |
98 |
{ |
99 |
got => $order_0_0->{totalgsti}, |
100 |
expected => 154.98, |
101 |
conf => '0 0', |
102 |
field => 'totalgsti' |
103 |
} |
104 |
); |
105 |
compare( |
106 |
{ |
107 |
got => $order_0_0->{totalgste}, |
108 |
expected => 147.60, |
109 |
conf => '0 0', |
110 |
field => 'totalgste' |
111 |
} |
112 |
); |
113 |
}; |
114 |
|
115 |
subtest 'Configuration 1: 1 1' => sub { |
116 |
plan tests => 7; |
117 |
$bookseller_module->mock( |
118 |
'fetch', |
119 |
sub { |
120 |
return { listincgst => 1, invoiceincgst => 1 }; |
121 |
} |
122 |
); |
123 |
|
124 |
my $biblionumber_1_1 = 43; |
125 |
my $order_1_1 = { |
126 |
biblionumber => $biblionumber_1_1, |
127 |
quantity => 2, |
128 |
listprice => 82.000000, |
129 |
unitprice => 73.800000, |
130 |
quantityreceived => 2, |
131 |
basketno => $basketno_1_1, |
132 |
invoiceid => $invoiceid_1_1, |
133 |
rrp => 82.00, |
134 |
ecost => 73.80, |
135 |
gstrate => 0.0500, |
136 |
discount => 10.0000, |
137 |
datereceived => $today |
138 |
}; |
139 |
|
140 |
$order_1_1 = C4::Acquisition::populate_order_with_prices( |
141 |
{ |
142 |
order => $order_1_1, |
143 |
booksellerid => 'just_something', |
144 |
ordering => 1, |
145 |
} |
146 |
); |
147 |
|
148 |
# Note that this configuration is *not* correct |
149 |
# gstvalue should be 7.03 instead of 7.02 |
150 |
compare( |
151 |
{ |
152 |
got => $order_1_1->{rrpgsti}, |
153 |
expected => 82.00, |
154 |
conf => '1 1', |
155 |
field => 'rrpgsti' |
156 |
} |
157 |
); |
158 |
compare( |
159 |
{ |
160 |
got => $order_1_1->{rrpgste}, |
161 |
expected => 78.10, |
162 |
conf => '1 1', |
163 |
field => 'rrpgsti' |
164 |
} |
165 |
); |
166 |
compare( |
167 |
{ |
168 |
got => $order_1_1->{ecostgsti}, |
169 |
expected => 73.80, |
170 |
conf => '1 1', |
171 |
field => 'ecostgsti' |
172 |
} |
173 |
); |
174 |
compare( |
175 |
{ |
176 |
got => $order_1_1->{ecostgste}, |
177 |
expected => 70.29, |
178 |
conf => '1 1', |
179 |
field => 'ecostgste' |
180 |
} |
181 |
); |
182 |
compare( |
183 |
{ |
184 |
got => $order_1_1->{gstvalue}, |
185 |
expected => 7.02, |
186 |
conf => '1 1', |
187 |
field => 'gstvalue' |
188 |
} |
189 |
); |
190 |
compare( |
191 |
{ |
192 |
got => $order_1_1->{totalgsti}, |
193 |
expected => 147.60, |
194 |
conf => '1 1', |
195 |
field => 'totalgsti' |
196 |
} |
197 |
); |
198 |
compare( |
199 |
{ |
200 |
got => $order_1_1->{totalgste}, |
201 |
expected => 140.58, |
202 |
conf => '1 1', |
203 |
field => 'totalgste' |
204 |
} |
205 |
); |
206 |
}; |
207 |
|
208 |
subtest 'Configuration 1: 1 0' => sub { |
209 |
plan tests => 7; |
210 |
$bookseller_module->mock( |
211 |
'fetch', |
212 |
sub { |
213 |
return { listincgst => 1, invoiceincgst => 0 }; |
214 |
} |
215 |
); |
216 |
|
217 |
my $biblionumber_1_0 = 44; |
218 |
my $order_1_0 = { |
219 |
biblionumber => $biblionumber_1_0, |
220 |
quantity => 2, |
221 |
listprice => 82.000000, |
222 |
unitprice => 73.804500, |
223 |
quantityreceived => 2, |
224 |
basketno => $basketno_1_1, |
225 |
invoiceid => $invoiceid_1_1, |
226 |
rrp => 82.01, |
227 |
ecost => 73.80, |
228 |
gstrate => 0.0500, |
229 |
discount => 10.0000, |
230 |
datereceived => $today |
231 |
}; |
232 |
|
233 |
$order_1_0 = C4::Acquisition::populate_order_with_prices( |
234 |
{ |
235 |
order => $order_1_0, |
236 |
booksellerid => 'just_something', |
237 |
ordering => 1, |
238 |
} |
239 |
); |
240 |
|
241 |
# Note that this configuration is *not* correct! |
242 |
# rrp gsti should be 82 (what we inserted!) |
243 |
# gstvalue should be 7.03 instead of 7.02 |
244 |
|
245 |
compare( |
246 |
{ |
247 |
got => $order_1_0->{rrpgsti}, |
248 |
expected => 82.01, |
249 |
conf => '1 0', |
250 |
field => 'rrpgsti' |
251 |
} |
252 |
); |
253 |
compare( |
254 |
{ |
255 |
got => $order_1_0->{rrpgste}, |
256 |
expected => 78.10, |
257 |
conf => '1 0', |
258 |
field => 'rrpgsti' |
259 |
} |
260 |
); |
261 |
compare( |
262 |
{ |
263 |
got => $order_1_0->{ecostgsti}, |
264 |
expected => 73.80, |
265 |
conf => '1 0', |
266 |
field => 'ecostgsti' |
267 |
} |
268 |
); |
269 |
compare( |
270 |
{ |
271 |
got => $order_1_0->{ecostgste}, |
272 |
expected => 70.29, |
273 |
conf => '1 0', |
274 |
field => 'ecostgste' |
275 |
} |
276 |
); |
277 |
compare( |
278 |
{ |
279 |
got => $order_1_0->{gstvalue}, |
280 |
expected => 7.02, |
281 |
conf => '1 0', |
282 |
field => 'gstvalue' |
283 |
} |
284 |
); |
285 |
compare( |
286 |
{ |
287 |
got => $order_1_0->{totalgsti}, |
288 |
expected => 147.60, |
289 |
conf => '1 0', |
290 |
field => 'totalgsti' |
291 |
} |
292 |
); |
293 |
compare( |
294 |
{ |
295 |
got => $order_1_0->{totalgste}, |
296 |
expected => 140.58, |
297 |
conf => '1 0', |
298 |
field => 'totalgste' |
299 |
} |
300 |
); |
301 |
}; |
302 |
|
303 |
subtest 'Configuration 1: 0 1' => sub { |
304 |
plan tests => 7; |
305 |
$bookseller_module->mock( |
306 |
'fetch', |
307 |
sub { |
308 |
return { listincgst => 0, invoiceincgst => 1 }; |
309 |
} |
310 |
); |
311 |
|
312 |
my $biblionumber_0_1 = 45; |
313 |
my $order_0_1 = { |
314 |
biblionumber => $biblionumber_0_1, |
315 |
quantity => 2, |
316 |
listprice => 82.000000, |
317 |
unitprice => 73.800000, |
318 |
quantityreceived => 2, |
319 |
basketno => $basketno_1_1, |
320 |
invoiceid => $invoiceid_1_1, |
321 |
rrp => 82.00, |
322 |
ecost => 73.80, |
323 |
gstrate => 0.0500, |
324 |
discount => 10.0000, |
325 |
datereceived => $today |
326 |
}; |
327 |
|
328 |
$order_0_1 = C4::Acquisition::populate_order_with_prices( |
329 |
{ |
330 |
order => $order_0_1, |
331 |
booksellerid => 'just_something', |
332 |
ordering => 1, |
333 |
} |
334 |
); |
335 |
|
336 |
# Note that this configuration is correct \o/ |
337 |
compare( |
338 |
{ |
339 |
got => $order_0_1->{rrpgsti}, |
340 |
expected => 86.10, |
341 |
conf => '1 0', |
342 |
field => 'rrpgsti' |
343 |
} |
344 |
); |
345 |
compare( |
346 |
{ |
347 |
got => $order_0_1->{rrpgste}, |
348 |
expected => 82.00, |
349 |
conf => '1 0', |
350 |
field => 'rrpgsti' |
351 |
} |
352 |
); |
353 |
compare( |
354 |
{ |
355 |
got => $order_0_1->{ecostgsti}, |
356 |
expected => 77.49, |
357 |
conf => '1 0', |
358 |
field => 'ecostgsti' |
359 |
} |
360 |
); |
361 |
compare( |
362 |
{ |
363 |
got => $order_0_1->{ecostgste}, |
364 |
expected => 73.80, |
365 |
conf => '1 0', |
366 |
field => 'ecostgste' |
367 |
} |
368 |
); |
369 |
compare( |
370 |
{ |
371 |
got => $order_0_1->{gstvalue}, |
372 |
expected => 7.38, |
373 |
conf => '1 0', |
374 |
field => 'gstvalue' |
375 |
} |
376 |
); |
377 |
compare( |
378 |
{ |
379 |
got => $order_0_1->{totalgsti}, |
380 |
expected => 154.98, |
381 |
conf => '1 0', |
382 |
field => 'totalgsti' |
383 |
} |
384 |
); |
385 |
compare( |
386 |
{ |
387 |
got => $order_0_1->{totalgste}, |
388 |
expected => 147.60, |
389 |
conf => '1 0', |
390 |
field => 'totalgste' |
391 |
} |
392 |
); |
393 |
}; |
394 |
} |
395 |
|
396 |
sub compare { |
397 |
my ($params) = @_; |
398 |
is( |
399 |
Koha::Number::Price->new( $params->{got} )->format, |
400 |
Koha::Number::Price->new( $params->{expected} )->format, |
401 |
"configuration $params->{conf}: $params->{field} should be correctly calculated" |
402 |
); |
403 |
} |