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, $basketno_1_0, $basketno_0_1 );
46 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_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},
255 subtest 'Configuration 1: 1 0 (Vendor List prices include tax / Invoice prices do not include tax)' => sub {
258 my $biblionumber_1_0 = 44;
260 biblionumber => $biblionumber_1_0,
264 quantityreceived => 2,
265 basketno => $basketno_1_1,
266 invoiceid => $invoiceid_1_1,
271 datereceived => $today
274 $order_1_0 = C4::Acquisition::populate_order_with_prices(
284 got => $order_1_0->{rrp_tax_included},
287 field => 'rrp_tax_included'
292 got => $order_1_0->{rrp_tax_excluded},
295 field => 'rrp_tax_excluded'
300 got => $order_1_0->{ecost_tax_included},
303 field => 'ecost_tax_included'
308 got => $order_1_0->{ecost_tax_excluded},
311 field => 'ecost_tax_excluded'
314 # If we order with unitprice = 0, tax is calculated from the ecost
315 # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
318 got => $order_1_0->{tax_value_on_ordering},
324 $order_1_0->{unitprice} = 70.29;
325 $order_1_0 = C4::Acquisition::populate_order_with_prices(
332 # If a unitprice is provided at ordering, we calculate the tax from that
335 got => $order_1_0->{tax_value_on_ordering},
342 $order_1_0 = C4::Acquisition::populate_order_with_prices(
352 got => $order_1_0->{unitprice_tax_included},
355 field => 'unitprice_tax_included'
360 got => $order_1_0->{unitprice_tax_excluded},
363 field => 'unitprice_tax_excluded'
368 got => $order_1_0->{tax_value_on_receiving},
376 subtest 'Configuration 1: 0 1 (Vendor List prices do not include tax / Invoice prices include tax)' => sub {
379 my $biblionumber_0_1 = 45;
381 biblionumber => $biblionumber_0_1,
385 quantityreceived => 2,
386 basketno => $basketno_1_1,
387 invoiceid => $invoiceid_1_1,
392 datereceived => $today
395 $order_0_1 = C4::Acquisition::populate_order_with_prices(
405 got => $order_0_1->{rrp_tax_included},
408 field => 'rrp_tax_included'
413 got => $order_0_1->{rrp_tax_excluded},
416 field => 'rrp_tax_excluded'
421 got => $order_0_1->{ecost_tax_included},
424 field => 'ecost_tax_included'
429 got => $order_0_1->{ecost_tax_excluded},
432 field => 'ecost_tax_excluded'
435 # If we order with unitprice = 0, tax is calculated from the ecost
436 # (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost
439 got => $order_0_1->{tax_value_on_ordering},
445 $order_0_1->{unitprice} = 77.490000;
446 $order_0_1 = C4::Acquisition::populate_order_with_prices(
453 # If a unitprice is provided at ordering, we calculate the tax from that
456 got => $order_0_1->{tax_value_on_ordering},
462 $order_0_1 = C4::Acquisition::populate_order_with_prices(
472 got => $order_0_1->{unitprice_tax_included},
475 field => 'unitprice_tax_included'
480 got => $order_0_1->{unitprice_tax_excluded},
483 field => 'unitprice_tax_excluded'
488 got => $order_0_1->{tax_value_on_receiving},
500 Koha::Number::Price->new( $params->{got} )->format,
501 Koha::Number::Price->new( $params->{expected} )->format,
502 "configuration $params->{conf}: $params->{field} should be correctly calculated"
507 for my $currency_format ( qw( US FR ) ) {
508 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
509 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
510 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );