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::Context');
19 use_ok('Koha::Number::Price');
21 t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
23 use Test::DBIx::Class;
25 my $db = Test::MockModule->new('Koha::Database');
26 $db->mock( _new_schema => sub { return Schema(); } );
27 Koha::Database::flush_schema_cache();
31 [ qw/ currency symbol rate active / ],
32 [ 'my_cur', '€', 1, 1, ],
35 [ qw/ id name listincgst invoiceincgst / ],
41 ], 'add currency fixtures';
43 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
45 my ( $basketno_0_0, $basketno_1_1 );
46 my ( $invoiceid_0_0, $invoiceid_1_1 );
49 for my $currency_format ( qw( US FR ) ) {
50 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
51 subtest 'Configuration 1: 0 0 (Vendor List prices do not include tax / Invoice prices do not include tax)' => sub {
54 my $biblionumber_0_0 = 42;
57 biblionumber => $biblionumber_0_0,
61 quantityreceived => 2,
62 basketno => $basketno_0_0,
63 invoiceid => $invoiceid_0_0,
68 datereceived => $today
70 $order_0_0 = C4::Acquisition::populate_order_with_prices(
80 got => $order_0_0->{rrp_tax_included},
83 field => 'rrp_tax_included'
88 got => $order_0_0->{rrp_tax_excluded},
91 field => 'rrp_tax_excluded'
96 got => $order_0_0->{ecost_tax_included},
99 field => 'ecost_tax_included'
104 got => $order_0_0->{ecost_tax_excluded},
107 field => 'ecost_tax_excluded'
112 got => $order_0_0->{tax_value_on_ordering},
119 $order_0_0 = C4::Acquisition::populate_order_with_prices(
129 got => $order_0_0->{unitprice_tax_included},
132 field => 'unitprice_tax_included'
137 got => $order_0_0->{unitprice_tax_excluded},
140 field => 'unitprice_tax_excluded'
145 got => $order_0_0->{tax_value_on_receiving},
153 subtest 'Configuration 1: 1 1 (Vendor List prices do include tax / Invoice prices include tax)' => sub {
156 my $biblionumber_1_1 = 43;
158 biblionumber => $biblionumber_1_1,
162 quantityreceived => 2,
163 basketno => $basketno_1_1,
164 invoiceid => $invoiceid_1_1,
169 datereceived => $today
172 $order_1_1 = C4::Acquisition::populate_order_with_prices(
182 got => $order_1_1->{rrp_tax_included},
185 field => 'rrp_tax_included'
190 got => $order_1_1->{rrp_tax_excluded},
193 field => 'rrp_tax_excluded'
198 got => $order_1_1->{ecost_tax_included},
201 field => 'ecost_tax_included'
206 got => $order_1_1->{ecost_tax_excluded},
209 field => 'ecost_tax_excluded'
214 got => $order_1_1->{tax_value_on_ordering},
221 $order_1_1 = C4::Acquisition::populate_order_with_prices(
231 got => $order_1_1->{unitprice_tax_included},
234 field => 'unitprice_tax_included'
239 got => $order_1_1->{unitprice_tax_excluded},
242 field => 'unitprice_tax_excluded'
247 got => $order_1_1->{tax_value_on_receiving},
254 # When unitprice is 0.00 C4::Acquisition->populate_order_with_prices() falls back to using ecost_tax_included and ecost_tax_excluded
256 biblionumber => $biblionumber_1_1,
260 quantityreceived => 1,
261 basketno => $basketno_1_1,
262 invoiceid => $invoiceid_1_1,
267 datereceived => $today
270 $order_1_1 = C4::Acquisition::populate_order_with_prices(
280 got => $order_1_1->{ecost_tax_included},
283 field => 'ecost_tax_included'
288 got => $order_1_1->{ecost_tax_excluded},
291 field => 'ecost_tax_excluded'
296 got => $order_1_1->{tax_value_on_ordering},
304 subtest 'Configuration 1: 1 0 (Vendor List prices include tax / Invoice prices do not include tax)' => sub {
307 my $biblionumber_1_0 = 44;
309 biblionumber => $biblionumber_1_0,
313 quantityreceived => 2,
314 basketno => $basketno_1_1,
315 invoiceid => $invoiceid_1_1,
320 datereceived => $today
323 $order_1_0 = C4::Acquisition::populate_order_with_prices(
333 got => $order_1_0->{rrp_tax_included},
336 field => 'rrp_tax_included'
341 got => $order_1_0->{rrp_tax_excluded},
344 field => 'rrp_tax_excluded'
349 got => $order_1_0->{ecost_tax_included},
352 field => 'ecost_tax_included'
357 got => $order_1_0->{ecost_tax_excluded},
360 field => 'ecost_tax_excluded'
363 # If we order with unitprice = 0, tax is calculated from the ecost
364 # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
367 got => $order_1_0->{tax_value_on_ordering},
373 $order_1_0->{unitprice} = 70.29;
374 $order_1_0 = C4::Acquisition::populate_order_with_prices(
381 # If a unitprice is provided at ordering, we calculate the tax from that
384 got => $order_1_0->{tax_value_on_ordering},
391 $order_1_0 = C4::Acquisition::populate_order_with_prices(
401 got => $order_1_0->{unitprice_tax_included},
404 field => 'unitprice_tax_included'
409 got => $order_1_0->{unitprice_tax_excluded},
412 field => 'unitprice_tax_excluded'
417 got => $order_1_0->{tax_value_on_receiving},
425 subtest 'Configuration 1: 0 1 (Vendor List prices do not include tax / Invoice prices include tax)' => sub {
428 my $biblionumber_0_1 = 45;
430 biblionumber => $biblionumber_0_1,
434 quantityreceived => 2,
435 basketno => $basketno_1_1,
436 invoiceid => $invoiceid_1_1,
441 datereceived => $today
444 $order_0_1 = C4::Acquisition::populate_order_with_prices(
454 got => $order_0_1->{rrp_tax_included},
457 field => 'rrp_tax_included'
462 got => $order_0_1->{rrp_tax_excluded},
465 field => 'rrp_tax_excluded'
470 got => $order_0_1->{ecost_tax_included},
473 field => 'ecost_tax_included'
478 got => $order_0_1->{ecost_tax_excluded},
481 field => 'ecost_tax_excluded'
484 # If we order with unitprice = 0, tax is calculated from the ecost
485 # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
488 got => $order_0_1->{tax_value_on_ordering},
494 $order_0_1->{unitprice} = 77.490000;
495 $order_0_1 = C4::Acquisition::populate_order_with_prices(
502 # If a unitprice is provided at ordering, we calculate the tax from that
505 got => $order_0_1->{tax_value_on_ordering},
511 $order_0_1 = C4::Acquisition::populate_order_with_prices(
521 got => $order_0_1->{unitprice_tax_included},
524 field => 'unitprice_tax_included'
529 got => $order_0_1->{unitprice_tax_excluded},
532 field => 'unitprice_tax_excluded'
537 got => $order_0_1->{tax_value_on_receiving},
550 Koha::Number::Price->new( $params->{got} )->format,
551 Koha::Number::Price->new( $params->{expected} )->format,
552 "configuration $params->{conf}: $params->{field} should be correctly calculated"
557 for my $currency_format ( qw( US FR ) ) {
558 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
559 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
560 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );