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',
84 got => $order_0_0->{rrp_tax_included},
87 field => 'rrp_tax_included'
92 got => $order_0_0->{rrp_tax_excluded},
95 field => 'rrp_tax_excluded'
100 got => $order_0_0->{ecost_tax_included},
103 field => 'ecost_tax_included'
108 got => $order_0_0->{ecost_tax_excluded},
111 field => 'ecost_tax_excluded'
116 got => $order_0_0->{tax_value_on_ordering},
123 $order_0_0 = C4::Acquisition::populate_order_with_prices(
126 booksellerid => 'just_something',
133 got => $order_0_0->{unitprice_tax_included},
136 field => 'unitprice_tax_included'
141 got => $order_0_0->{unitprice_tax_excluded},
144 field => 'unitprice_tax_excluded'
149 got => $order_0_0->{tax_value_on_receiving},
157 subtest 'Configuration 1: 1 1' => sub {
159 $bookseller_module->mock(
162 return { listincgst => 1, invoiceincgst => 1 };
166 my $biblionumber_1_1 = 43;
168 biblionumber => $biblionumber_1_1,
170 listprice => 82.000000,
171 unitprice => 73.800000,
172 quantityreceived => 2,
173 basketno => $basketno_1_1,
174 invoiceid => $invoiceid_1_1,
179 datereceived => $today
182 $order_1_1 = C4::Acquisition::populate_order_with_prices(
185 booksellerid => 'just_something',
192 got => $order_1_1->{rrp_tax_included},
195 field => 'rrp_tax_included'
200 got => $order_1_1->{rrp_tax_excluded},
203 field => 'rrp_tax_excluded'
208 got => $order_1_1->{ecost_tax_included},
211 field => 'ecost_tax_included'
216 got => $order_1_1->{ecost_tax_excluded},
219 field => 'ecost_tax_excluded'
224 got => $order_1_1->{tax_value_on_ordering},
231 $order_1_1 = C4::Acquisition::populate_order_with_prices(
234 booksellerid => 'just_something',
241 got => $order_1_1->{unitprice_tax_included},
244 field => 'unitprice_tax_included'
249 got => $order_1_1->{unitprice_tax_excluded},
252 field => 'unitprice_tax_excluded'
257 got => $order_1_1->{tax_value_on_receiving},
265 subtest 'Configuration 1: 1 0' => sub {
267 $bookseller_module->mock(
270 return { listincgst => 1, invoiceincgst => 0 };
274 my $biblionumber_1_0 = 44;
276 biblionumber => $biblionumber_1_0,
278 listprice => 82.000000,
279 unitprice => 70.290000,
280 quantityreceived => 2,
281 basketno => $basketno_1_1,
282 invoiceid => $invoiceid_1_1,
287 datereceived => $today
290 $order_1_0 = C4::Acquisition::populate_order_with_prices(
293 booksellerid => 'just_something',
300 got => $order_1_0->{rrp_tax_included},
303 field => 'rrp_tax_included'
308 got => $order_1_0->{rrp_tax_excluded},
311 field => 'rrp_tax_excluded'
316 got => $order_1_0->{ecost_tax_included},
319 field => 'ecost_tax_included'
324 got => $order_1_0->{ecost_tax_excluded},
327 field => 'ecost_tax_excluded'
332 got => $order_1_0->{tax_value_on_ordering},
339 $order_1_0 = C4::Acquisition::populate_order_with_prices(
342 booksellerid => 'just_something',
349 got => $order_1_0->{unitprice_tax_included},
352 field => 'unitprice_tax_included'
357 got => $order_1_0->{unitprice_tax_excluded},
360 field => 'unitprice_tax_excluded'
365 got => $order_1_0->{tax_value_on_receiving},
373 subtest 'Configuration 1: 0 1' => sub {
375 $bookseller_module->mock(
378 return { listincgst => 0, invoiceincgst => 1 };
382 my $biblionumber_0_1 = 45;
384 biblionumber => $biblionumber_0_1,
386 listprice => 82.000000,
387 unitprice => 77.490000,
388 quantityreceived => 2,
389 basketno => $basketno_1_1,
390 invoiceid => $invoiceid_1_1,
395 datereceived => $today
398 $order_0_1 = C4::Acquisition::populate_order_with_prices(
401 booksellerid => 'just_something',
408 got => $order_0_1->{rrp_tax_included},
411 field => 'rrp_tax_included'
416 got => $order_0_1->{rrp_tax_excluded},
419 field => 'rrp_tax_excluded'
424 got => $order_0_1->{ecost_tax_included},
427 field => 'ecost_tax_included'
432 got => $order_0_1->{ecost_tax_excluded},
435 field => 'ecost_tax_excluded'
440 got => $order_0_1->{tax_value_on_ordering},
447 $order_0_1 = C4::Acquisition::populate_order_with_prices(
450 booksellerid => 'just_something',
457 got => $order_0_1->{unitprice_tax_included},
460 field => 'unitprice_tax_included'
465 got => $order_0_1->{unitprice_tax_excluded},
468 field => 'unitprice_tax_excluded'
473 got => $order_0_1->{tax_value_on_receiving},
485 Koha::Number::Price->new( $params->{got} )->format,
486 Koha::Number::Price->new( $params->{expected} )->format,
487 "configuration $params->{conf}: $params->{field} should be correctly calculated"
492 for my $currency_format ( qw( US FR ) ) {
493 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
494 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
495 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );