2 use Test::More tests => 16;
8 my $context_module = t::lib::Mocks::mock_dbh;
9 use_ok('C4::Acquisition');
10 use_ok('C4::Bookseller');
11 use_ok('C4::Context');
12 use_ok('Koha::Number::Price');
15 t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
17 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
19 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
20 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
23 for my $currency_format ( qw( US FR ) ) {
24 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
25 subtest 'Configuration 1: 0 0' => sub {
27 $bookseller_module->mock(
30 return { listincgst => 0, invoiceincgst => 0 };
34 my $biblionumber_0_0 = 42;
37 biblionumber => $biblionumber_0_0,
39 listprice => 82.000000,
40 unitprice => 73.80000,
41 quantityreceived => 2,
42 basketno => $basketno_0_0,
43 invoiceid => $invoiceid_0_0,
48 datereceived => $today
50 $order_0_0 = C4::Acquisition::populate_order_with_prices(
53 booksellerid => 'just_something',
58 # Note that this configuration is correct \o/
61 got => $order_0_0->{rrpgsti},
69 got => $order_0_0->{rrpgste},
77 got => $order_0_0->{ecostgsti},
85 got => $order_0_0->{ecostgste},
93 got => $order_0_0->{gstvalue},
101 got => $order_0_0->{totalgsti},
109 got => $order_0_0->{totalgste},
116 $order_0_0 = C4::Acquisition::populate_order_with_prices(
119 booksellerid => 'just_something',
123 # Note that this configuration is *not* correct!
124 # unitpricegsti should be 75.28
125 # totalgst should be 150.56
128 got => $order_0_0->{unitpricegsti},
131 field => 'unitpricegsti'
136 got => $order_0_0->{unitpricegste},
139 field => 'unitpricegste'
144 got => $order_0_0->{gstvalue},
152 got => $order_0_0->{totalgsti},
160 got => $order_0_0->{totalgste},
168 subtest 'Configuration 1: 1 1' => sub {
170 $bookseller_module->mock(
173 return { listincgst => 1, invoiceincgst => 1 };
177 my $biblionumber_1_1 = 43;
179 biblionumber => $biblionumber_1_1,
181 listprice => 82.000000,
182 unitprice => 73.800000,
183 quantityreceived => 2,
184 basketno => $basketno_1_1,
185 invoiceid => $invoiceid_1_1,
190 datereceived => $today
193 $order_1_1 = C4::Acquisition::populate_order_with_prices(
196 booksellerid => 'just_something',
201 # Note that this configuration is *not* correct
202 # gstvalue should be 7.03 instead of 7.02
205 got => $order_1_1->{rrpgsti},
213 got => $order_1_1->{rrpgste},
221 got => $order_1_1->{ecostgsti},
229 got => $order_1_1->{ecostgste},
237 got => $order_1_1->{gstvalue},
245 got => $order_1_1->{totalgsti},
253 got => $order_1_1->{totalgste},
260 $order_1_1 = C4::Acquisition::populate_order_with_prices(
263 booksellerid => 'just_something',
267 # Note that this configuration is *not* correct!
268 # gstvalue should be 7.03
271 got => $order_1_1->{unitpricegsti},
274 field => 'unitpricegsti'
279 got => $order_1_1->{unitpricegste},
282 field => 'unitpricegste'
287 got => $order_1_1->{gstvalue},
295 got => $order_1_1->{totalgsti},
303 got => $order_1_1->{totalgste},
311 subtest 'Configuration 1: 1 0' => sub {
313 $bookseller_module->mock(
316 return { listincgst => 1, invoiceincgst => 0 };
320 my $biblionumber_1_0 = 44;
322 biblionumber => $biblionumber_1_0,
324 listprice => 82.000000,
325 unitprice => 73.804500,
326 quantityreceived => 2,
327 basketno => $basketno_1_1,
328 invoiceid => $invoiceid_1_1,
333 datereceived => $today
336 $order_1_0 = C4::Acquisition::populate_order_with_prices(
339 booksellerid => 'just_something',
344 # Note that this configuration is *not* correct!
345 # rrp gsti should be 82 (what we inserted!)
346 # gstvalue should be 7.03 instead of 7.02
350 got => $order_1_0->{rrpgsti},
358 got => $order_1_0->{rrpgste},
366 got => $order_1_0->{ecostgsti},
374 got => $order_1_0->{ecostgste},
382 got => $order_1_0->{gstvalue},
390 got => $order_1_0->{totalgsti},
398 got => $order_1_0->{totalgste},
405 $order_1_0 = C4::Acquisition::populate_order_with_prices(
408 booksellerid => 'just_something',
412 # Note that this configuration is *not* correct!
413 # unitpricegsti should be 71.69
414 # totalgsti should be 143.38
415 # gstvalue should be 7.03
418 got => $order_1_0->{unitpricegsti},
421 field => 'unitpricegsti'
426 got => $order_1_0->{unitpricegste},
429 field => 'unitpricegste'
434 got => $order_1_0->{gstvalue},
442 got => $order_1_0->{totalgsti},
450 got => $order_1_0->{totalgste},
458 subtest 'Configuration 1: 0 1' => sub {
460 $bookseller_module->mock(
463 return { listincgst => 0, invoiceincgst => 1 };
467 my $biblionumber_0_1 = 45;
469 biblionumber => $biblionumber_0_1,
471 listprice => 82.000000,
472 unitprice => 73.800000,
473 quantityreceived => 2,
474 basketno => $basketno_1_1,
475 invoiceid => $invoiceid_1_1,
480 datereceived => $today
483 $order_0_1 = C4::Acquisition::populate_order_with_prices(
486 booksellerid => 'just_something',
491 # Note that this configuration is correct \o/
494 got => $order_0_1->{rrpgsti},
502 got => $order_0_1->{rrpgste},
510 got => $order_0_1->{ecostgsti},
518 got => $order_0_1->{ecostgste},
526 got => $order_0_1->{gstvalue},
534 got => $order_0_1->{totalgsti},
542 got => $order_0_1->{totalgste},
549 $order_0_1 = C4::Acquisition::populate_order_with_prices(
552 booksellerid => 'just_something',
556 # Note that this configuration is correct
559 got => $order_0_1->{unitpricegsti},
562 field => 'unitpricegsti'
567 got => $order_0_1->{unitpricegste},
570 field => 'unitpricegste'
575 got => $order_0_1->{gstvalue},
583 got => $order_0_1->{totalgsti},
591 got => $order_0_1->{totalgste},
603 Koha::Number::Price->new( $params->{got} )->format,
604 Koha::Number::Price->new( $params->{expected} )->format,
605 "configuration $params->{conf}: $params->{field} should be correctly calculated"
610 for my $currency_format ( qw( US FR ) ) {
611 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
612 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
613 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );