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',
124 # Note that this configuration is correct \o/
127 got => $order_0_0->{unitpricegsti},
130 field => 'unitpricegsti'
135 got => $order_0_0->{unitpricegste},
138 field => 'unitpricegste'
143 got => $order_0_0->{gstvalue},
151 got => $order_0_0->{totalgsti},
159 got => $order_0_0->{totalgste},
167 subtest 'Configuration 1: 1 1' => sub {
169 $bookseller_module->mock(
172 return { listincgst => 1, invoiceincgst => 1 };
176 my $biblionumber_1_1 = 43;
178 biblionumber => $biblionumber_1_1,
180 listprice => 82.000000,
181 unitprice => 73.800000,
182 quantityreceived => 2,
183 basketno => $basketno_1_1,
184 invoiceid => $invoiceid_1_1,
189 datereceived => $today
192 $order_1_1 = C4::Acquisition::populate_order_with_prices(
195 booksellerid => 'just_something',
200 # Note that this configuration is *not* correct
201 # gstvalue should be 7.03 instead of 7.02
204 got => $order_1_1->{rrpgsti},
212 got => $order_1_1->{rrpgste},
220 got => $order_1_1->{ecostgsti},
228 got => $order_1_1->{ecostgste},
236 got => $order_1_1->{gstvalue},
244 got => $order_1_1->{totalgsti},
252 got => $order_1_1->{totalgste},
259 $order_1_1 = C4::Acquisition::populate_order_with_prices(
262 booksellerid => 'just_something',
266 # Note that this configuration is *not* correct!
267 # gstvalue should be 7.03
270 got => $order_1_1->{unitpricegsti},
273 field => 'unitpricegsti'
278 got => $order_1_1->{unitpricegste},
281 field => 'unitpricegste'
286 got => $order_1_1->{gstvalue},
294 got => $order_1_1->{totalgsti},
302 got => $order_1_1->{totalgste},
310 subtest 'Configuration 1: 1 0' => sub {
312 $bookseller_module->mock(
315 return { listincgst => 1, invoiceincgst => 0 };
319 my $biblionumber_1_0 = 44;
321 biblionumber => $biblionumber_1_0,
323 listprice => 82.000000,
324 unitprice => 73.804500,
325 quantityreceived => 2,
326 basketno => $basketno_1_1,
327 invoiceid => $invoiceid_1_1,
332 datereceived => $today
335 $order_1_0 = C4::Acquisition::populate_order_with_prices(
338 booksellerid => 'just_something',
343 # Note that this configuration is *not* correct!
344 # rrp gsti should be 82 (what we inserted!)
345 # => Actually we need to fix the inserted value (here we have 82.01 in DB)
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 # gstvalue should be 7.03
416 got => $order_1_0->{unitpricegsti},
419 field => 'unitpricegsti'
424 got => $order_1_0->{unitpricegste},
427 field => 'unitpricegste'
432 got => $order_1_0->{gstvalue},
440 got => $order_1_0->{totalgsti},
448 got => $order_1_0->{totalgste},
456 subtest 'Configuration 1: 0 1' => sub {
458 $bookseller_module->mock(
461 return { listincgst => 0, invoiceincgst => 1 };
465 my $biblionumber_0_1 = 45;
467 biblionumber => $biblionumber_0_1,
469 listprice => 82.000000,
470 unitprice => 73.800000,
471 quantityreceived => 2,
472 basketno => $basketno_1_1,
473 invoiceid => $invoiceid_1_1,
478 datereceived => $today
481 $order_0_1 = C4::Acquisition::populate_order_with_prices(
484 booksellerid => 'just_something',
489 # Note that this configuration is correct \o/
492 got => $order_0_1->{rrpgsti},
500 got => $order_0_1->{rrpgste},
508 got => $order_0_1->{ecostgsti},
516 got => $order_0_1->{ecostgste},
524 got => $order_0_1->{gstvalue},
532 got => $order_0_1->{totalgsti},
540 got => $order_0_1->{totalgste},
547 $order_0_1 = C4::Acquisition::populate_order_with_prices(
550 booksellerid => 'just_something',
554 # Note that this configuration is correct
557 got => $order_0_1->{unitpricegsti},
560 field => 'unitpricegsti'
565 got => $order_0_1->{unitpricegste},
568 field => 'unitpricegste'
573 got => $order_0_1->{gstvalue},
581 got => $order_0_1->{totalgsti},
589 got => $order_0_1->{totalgste},
601 Koha::Number::Price->new( $params->{got} )->format,
602 Koha::Number::Price->new( $params->{expected} )->format,
603 "configuration $params->{conf}: $params->{field} should be correctly calculated"
608 for my $currency_format ( qw( US FR ) ) {
609 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
610 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
611 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );