7 use Module::Load::Conditional qw/check_install/;
10 if ( check_install( module => 'Test::DBIx::Class' ) ) {
13 plan skip_all => "Need Test::DBIx::Class"
17 use_ok('C4::Acquisition');
18 use_ok('C4::Bookseller');
19 use_ok('C4::Context');
20 use_ok('Koha::Number::Price');
22 t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
24 use Test::DBIx::Class {
25 schema_class => 'Koha::Schema',
26 connect_info => ['dbi:SQLite:dbname=:memory:','',''],
27 connect_opts => { name_sep => '.', quote_char => '`', },
28 fixture_class => '::Populate',
31 my $db = Test::MockModule->new('Koha::Database');
32 $db->mock( _new_schema => sub { return Schema(); } );
36 [ qw/ currency symbol rate active / ],
37 [[ 'my_cur', '€', 1, 1, ]],
39 ], 'add currency fixtures';
41 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
43 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
44 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
47 for my $currency_format ( qw( US FR ) ) {
48 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
49 subtest 'Configuration 1: 0 0' => sub {
51 $bookseller_module->mock(
54 return { listincgst => 0, invoiceincgst => 0 };
58 my $biblionumber_0_0 = 42;
61 biblionumber => $biblionumber_0_0,
63 listprice => 82.000000,
64 unitprice => 73.80000,
65 quantityreceived => 2,
66 basketno => $basketno_0_0,
67 invoiceid => $invoiceid_0_0,
72 datereceived => $today
74 $order_0_0 = C4::Acquisition::populate_order_with_prices(
77 booksellerid => 'just_something',
82 # Note that this configuration is correct \o/
85 got => $order_0_0->{rrp_tax_included},
88 field => 'rrp_tax_included'
93 got => $order_0_0->{rrp_tax_excluded},
96 field => 'rrp_tax_excluded'
101 got => $order_0_0->{ecost_tax_included},
104 field => 'ecost_tax_included'
109 got => $order_0_0->{ecost_tax_excluded},
112 field => 'ecost_tax_excluded'
117 got => $order_0_0->{tax_value},
125 got => $order_0_0->{total_tax_included},
128 field => 'total_tax_included'
133 got => $order_0_0->{total_tax_excluded},
136 field => 'total_tax_excluded'
140 $order_0_0 = C4::Acquisition::populate_order_with_prices(
143 booksellerid => 'just_something',
148 # Note that this configuration is correct \o/
151 got => $order_0_0->{unitprice_tax_included},
154 field => 'unitprice_tax_included'
159 got => $order_0_0->{unitprice_tax_excluded},
162 field => 'unitprice_tax_excluded'
167 got => $order_0_0->{tax_value},
175 got => $order_0_0->{total_tax_included},
178 field => 'total_tax_included'
183 got => $order_0_0->{total_tax_excluded},
186 field => 'total_tax_excluded'
191 subtest 'Configuration 1: 1 1' => sub {
193 $bookseller_module->mock(
196 return { listincgst => 1, invoiceincgst => 1 };
200 my $biblionumber_1_1 = 43;
202 biblionumber => $biblionumber_1_1,
204 listprice => 82.000000,
205 unitprice => 73.800000,
206 quantityreceived => 2,
207 basketno => $basketno_1_1,
208 invoiceid => $invoiceid_1_1,
213 datereceived => $today
216 $order_1_1 = C4::Acquisition::populate_order_with_prices(
219 booksellerid => 'just_something',
224 # Note that this configuration is *not* correct
225 # tax_value should be 7.03 instead of 7.02
228 got => $order_1_1->{rrp_tax_included},
231 field => 'rrp_tax_included'
236 got => $order_1_1->{rrp_tax_excluded},
239 field => 'rrp_tax_excluded'
244 got => $order_1_1->{ecost_tax_included},
247 field => 'ecost_tax_included'
252 got => $order_1_1->{ecost_tax_excluded},
255 field => 'ecost_tax_excluded'
260 got => $order_1_1->{tax_value},
268 got => $order_1_1->{total_tax_included},
271 field => 'total_tax_included'
276 got => $order_1_1->{total_tax_excluded},
279 field => 'total_tax_excluded'
283 $order_1_1 = C4::Acquisition::populate_order_with_prices(
286 booksellerid => 'just_something',
290 # Note that this configuration is *not* correct!
291 # tax_value should be 7.03
294 got => $order_1_1->{unitprice_tax_included},
297 field => 'unitprice_tax_included'
302 got => $order_1_1->{unitprice_tax_excluded},
305 field => 'unitprice_tax_excluded'
310 got => $order_1_1->{tax_value},
318 got => $order_1_1->{total_tax_included},
321 field => 'total_tax_included'
326 got => $order_1_1->{total_tax_excluded},
329 field => 'total_tax_excluded'
334 subtest 'Configuration 1: 1 0' => sub {
336 $bookseller_module->mock(
339 return { listincgst => 1, invoiceincgst => 0 };
343 my $biblionumber_1_0 = 44;
345 biblionumber => $biblionumber_1_0,
347 listprice => 82.000000,
348 unitprice => 73.804500,
349 quantityreceived => 2,
350 basketno => $basketno_1_1,
351 invoiceid => $invoiceid_1_1,
356 datereceived => $today
359 $order_1_0 = C4::Acquisition::populate_order_with_prices(
362 booksellerid => 'just_something',
367 # Note that this configuration is *not* correct!
368 # rrp_tax_included should be 82 (what we inserted!)
369 # tax_value should be 7.03 instead of 7.02
373 got => $order_1_0->{rrp_tax_included},
376 field => 'rrp_tax_included'
381 got => $order_1_0->{rrp_tax_excluded},
384 field => 'rrp_tax_excluded'
389 got => $order_1_0->{ecost_tax_included},
392 field => 'ecost_tax_included'
397 got => $order_1_0->{ecost_tax_excluded},
400 field => 'ecost_tax_excluded'
405 got => $order_1_0->{tax_value},
413 got => $order_1_0->{total_tax_included},
416 field => 'total_tax_included'
421 got => $order_1_0->{total_tax_excluded},
424 field => 'total_tax_excluded'
428 $order_1_0 = C4::Acquisition::populate_order_with_prices(
431 booksellerid => 'just_something',
435 # Note that this configuration is *not* correct!
436 # gstvalue should be 7.03
439 got => $order_1_0->{unitprice_tax_included},
442 field => 'unitprice_tax_included'
447 got => $order_1_0->{unitprice_tax_excluded},
450 field => 'unitprice_tax_excluded'
455 got => $order_1_0->{tax_value},
463 got => $order_1_0->{total_tax_included},
466 field => 'total_tax_included'
471 got => $order_1_0->{total_tax_excluded},
474 field => 'total_tax_excluded'
479 subtest 'Configuration 1: 0 1' => sub {
481 $bookseller_module->mock(
484 return { listincgst => 0, invoiceincgst => 1 };
488 my $biblionumber_0_1 = 45;
490 biblionumber => $biblionumber_0_1,
492 listprice => 82.000000,
493 unitprice => 73.800000,
494 quantityreceived => 2,
495 basketno => $basketno_1_1,
496 invoiceid => $invoiceid_1_1,
501 datereceived => $today
504 $order_0_1 = C4::Acquisition::populate_order_with_prices(
507 booksellerid => 'just_something',
512 # Note that this configuration is correct \o/
515 got => $order_0_1->{rrp_tax_included},
518 field => 'rrp_tax_included'
523 got => $order_0_1->{rrp_tax_excluded},
526 field => 'rrp_tax_excluded'
531 got => $order_0_1->{ecost_tax_included},
534 field => 'ecost_tax_included'
539 got => $order_0_1->{ecost_tax_excluded},
542 field => 'ecost_tax_excluded'
547 got => $order_0_1->{tax_value},
555 got => $order_0_1->{total_tax_included},
558 field => 'total_tax_included'
563 got => $order_0_1->{total_tax_excluded},
566 field => 'total_tax_excluded'
570 $order_0_1 = C4::Acquisition::populate_order_with_prices(
573 booksellerid => 'just_something',
577 # Note that this configuration is correct
580 got => $order_0_1->{unitprice_tax_included},
583 field => 'unitprice_tax_included'
588 got => $order_0_1->{unitprice_tax_excluded},
591 field => 'unitprice_tax_excluded'
596 got => $order_0_1->{tax_value},
604 got => $order_0_1->{total_tax_included},
607 field => 'total_tax_included'
612 got => $order_0_1->{total_tax_excluded},
615 field => 'total_tax_excluded'
624 Koha::Number::Price->new( $params->{got} )->format,
625 Koha::Number::Price->new( $params->{expected} )->format,
626 "configuration $params->{conf}: $params->{field} should be correctly calculated"
631 for my $currency_format ( qw( US FR ) ) {
632 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
633 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
634 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );