2 use Test::More tests => 17;
8 use_ok('C4::Acquisition');
9 use_ok('C4::Bookseller');
10 use_ok('C4::Context');
11 use_ok('Koha::Number::Price');
14 t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
16 use Test::DBIx::Class {
17 schema_class => 'Koha::Schema',
18 connect_info => ['dbi:SQLite:dbname=:memory:','',''],
19 connect_opts => { name_sep => '.', quote_char => '`', },
20 fixture_class => '::Populate',
23 my $db = Test::MockModule->new('Koha::Database');
24 $db->mock( _new_schema => sub { return Schema(); } );
28 [ qw/ currency symbol rate active / ],
29 [[ 'my_cur', '€', 1, 1, ]],
31 ], 'add currency fixtures';
33 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
35 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
36 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
39 for my $currency_format ( qw( US FR ) ) {
40 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
41 subtest 'Configuration 1: 0 0' => sub {
43 $bookseller_module->mock(
46 return { listincgst => 0, invoiceincgst => 0 };
50 my $biblionumber_0_0 = 42;
53 biblionumber => $biblionumber_0_0,
55 listprice => 82.000000,
56 unitprice => 73.80000,
57 quantityreceived => 2,
58 basketno => $basketno_0_0,
59 invoiceid => $invoiceid_0_0,
64 datereceived => $today
66 $order_0_0 = C4::Acquisition::populate_order_with_prices(
69 booksellerid => 'just_something',
74 # Note that this configuration is correct \o/
77 got => $order_0_0->{rrpgsti},
85 got => $order_0_0->{rrpgste},
93 got => $order_0_0->{ecostgsti},
101 got => $order_0_0->{ecostgste},
109 got => $order_0_0->{gstvalue},
117 got => $order_0_0->{totalgsti},
125 got => $order_0_0->{totalgste},
132 $order_0_0 = C4::Acquisition::populate_order_with_prices(
135 booksellerid => 'just_something',
140 # Note that this configuration is correct \o/
143 got => $order_0_0->{unitpricegsti},
146 field => 'unitpricegsti'
151 got => $order_0_0->{unitpricegste},
154 field => 'unitpricegste'
159 got => $order_0_0->{gstvalue},
167 got => $order_0_0->{totalgsti},
175 got => $order_0_0->{totalgste},
183 subtest 'Configuration 1: 1 1' => sub {
185 $bookseller_module->mock(
188 return { listincgst => 1, invoiceincgst => 1 };
192 my $biblionumber_1_1 = 43;
194 biblionumber => $biblionumber_1_1,
196 listprice => 82.000000,
197 unitprice => 73.800000,
198 quantityreceived => 2,
199 basketno => $basketno_1_1,
200 invoiceid => $invoiceid_1_1,
205 datereceived => $today
208 $order_1_1 = C4::Acquisition::populate_order_with_prices(
211 booksellerid => 'just_something',
216 # Note that this configuration is *not* correct
217 # gstvalue should be 7.03 instead of 7.02
220 got => $order_1_1->{rrpgsti},
228 got => $order_1_1->{rrpgste},
236 got => $order_1_1->{ecostgsti},
244 got => $order_1_1->{ecostgste},
252 got => $order_1_1->{gstvalue},
260 got => $order_1_1->{totalgsti},
268 got => $order_1_1->{totalgste},
275 $order_1_1 = C4::Acquisition::populate_order_with_prices(
278 booksellerid => 'just_something',
282 # Note that this configuration is *not* correct!
283 # gstvalue should be 7.03
286 got => $order_1_1->{unitpricegsti},
289 field => 'unitpricegsti'
294 got => $order_1_1->{unitpricegste},
297 field => 'unitpricegste'
302 got => $order_1_1->{gstvalue},
310 got => $order_1_1->{totalgsti},
318 got => $order_1_1->{totalgste},
326 subtest 'Configuration 1: 1 0' => sub {
328 $bookseller_module->mock(
331 return { listincgst => 1, invoiceincgst => 0 };
335 my $biblionumber_1_0 = 44;
337 biblionumber => $biblionumber_1_0,
339 listprice => 82.000000,
340 unitprice => 73.804500,
341 quantityreceived => 2,
342 basketno => $basketno_1_1,
343 invoiceid => $invoiceid_1_1,
348 datereceived => $today
351 $order_1_0 = C4::Acquisition::populate_order_with_prices(
354 booksellerid => 'just_something',
359 # Note that this configuration is *not* correct!
360 # rrp gsti should be 82 (what we inserted!)
361 # => Actually we need to fix the inserted value (here we have 82.01 in DB)
362 # gstvalue should be 7.03 instead of 7.02
366 got => $order_1_0->{rrpgsti},
374 got => $order_1_0->{rrpgste},
382 got => $order_1_0->{ecostgsti},
390 got => $order_1_0->{ecostgste},
398 got => $order_1_0->{gstvalue},
406 got => $order_1_0->{totalgsti},
414 got => $order_1_0->{totalgste},
421 $order_1_0 = C4::Acquisition::populate_order_with_prices(
424 booksellerid => 'just_something',
428 # Note that this configuration is *not* correct!
429 # gstvalue should be 7.03
432 got => $order_1_0->{unitpricegsti},
435 field => 'unitpricegsti'
440 got => $order_1_0->{unitpricegste},
443 field => 'unitpricegste'
448 got => $order_1_0->{gstvalue},
456 got => $order_1_0->{totalgsti},
464 got => $order_1_0->{totalgste},
472 subtest 'Configuration 1: 0 1' => sub {
474 $bookseller_module->mock(
477 return { listincgst => 0, invoiceincgst => 1 };
481 my $biblionumber_0_1 = 45;
483 biblionumber => $biblionumber_0_1,
485 listprice => 82.000000,
486 unitprice => 73.800000,
487 quantityreceived => 2,
488 basketno => $basketno_1_1,
489 invoiceid => $invoiceid_1_1,
494 datereceived => $today
497 $order_0_1 = C4::Acquisition::populate_order_with_prices(
500 booksellerid => 'just_something',
505 # Note that this configuration is correct \o/
508 got => $order_0_1->{rrpgsti},
516 got => $order_0_1->{rrpgste},
524 got => $order_0_1->{ecostgsti},
532 got => $order_0_1->{ecostgste},
540 got => $order_0_1->{gstvalue},
548 got => $order_0_1->{totalgsti},
556 got => $order_0_1->{totalgste},
563 $order_0_1 = C4::Acquisition::populate_order_with_prices(
566 booksellerid => 'just_something',
570 # Note that this configuration is correct
573 got => $order_0_1->{unitpricegsti},
576 field => 'unitpricegsti'
581 got => $order_0_1->{unitpricegste},
584 field => 'unitpricegste'
589 got => $order_0_1->{gstvalue},
597 got => $order_0_1->{totalgsti},
605 got => $order_0_1->{totalgste},
617 Koha::Number::Price->new( $params->{got} )->format,
618 Koha::Number::Price->new( $params->{expected} )->format,
619 "configuration $params->{conf}: $params->{field} should be correctly calculated"
624 for my $currency_format ( qw( US FR ) ) {
625 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
626 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
627 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );