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(); } );
30 [ qw/ currency symbol rate active / ],
31 [[ 'my_cur', '€', 1, 1, ]],
34 [ qw/ id name listincgst invoiceincgst / ],
40 ], 'add currency fixtures';
42 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
44 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
45 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
48 for my $currency_format ( qw( US FR ) ) {
49 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
50 subtest 'Configuration 1: 0 0' => sub {
53 my $biblionumber_0_0 = 42;
56 biblionumber => $biblionumber_0_0,
58 listprice => 82.000000,
59 unitprice => 73.80000,
60 quantityreceived => 2,
61 basketno => $basketno_0_0,
62 invoiceid => $invoiceid_0_0,
67 datereceived => $today
69 $order_0_0 = C4::Acquisition::populate_order_with_prices(
79 got => $order_0_0->{rrp_tax_included},
82 field => 'rrp_tax_included'
87 got => $order_0_0->{rrp_tax_excluded},
90 field => 'rrp_tax_excluded'
95 got => $order_0_0->{ecost_tax_included},
98 field => 'ecost_tax_included'
103 got => $order_0_0->{ecost_tax_excluded},
106 field => 'ecost_tax_excluded'
111 got => $order_0_0->{tax_value_on_ordering},
118 $order_0_0 = C4::Acquisition::populate_order_with_prices(
128 got => $order_0_0->{unitprice_tax_included},
131 field => 'unitprice_tax_included'
136 got => $order_0_0->{unitprice_tax_excluded},
139 field => 'unitprice_tax_excluded'
144 got => $order_0_0->{tax_value_on_receiving},
152 subtest 'Configuration 1: 1 1' => sub {
155 my $biblionumber_1_1 = 43;
157 biblionumber => $biblionumber_1_1,
159 listprice => 82.000000,
160 unitprice => 73.800000,
161 quantityreceived => 2,
162 basketno => $basketno_1_1,
163 invoiceid => $invoiceid_1_1,
168 datereceived => $today
171 $order_1_1 = C4::Acquisition::populate_order_with_prices(
181 got => $order_1_1->{rrp_tax_included},
184 field => 'rrp_tax_included'
189 got => $order_1_1->{rrp_tax_excluded},
192 field => 'rrp_tax_excluded'
197 got => $order_1_1->{ecost_tax_included},
200 field => 'ecost_tax_included'
205 got => $order_1_1->{ecost_tax_excluded},
208 field => 'ecost_tax_excluded'
213 got => $order_1_1->{tax_value_on_ordering},
220 $order_1_1 = C4::Acquisition::populate_order_with_prices(
230 got => $order_1_1->{unitprice_tax_included},
233 field => 'unitprice_tax_included'
238 got => $order_1_1->{unitprice_tax_excluded},
241 field => 'unitprice_tax_excluded'
246 got => $order_1_1->{tax_value_on_receiving},
254 subtest 'Configuration 1: 1 0' => sub {
257 my $biblionumber_1_0 = 44;
259 biblionumber => $biblionumber_1_0,
261 listprice => 82.000000,
262 unitprice => 70.290000,
263 quantityreceived => 2,
264 basketno => $basketno_1_1,
265 invoiceid => $invoiceid_1_1,
270 datereceived => $today
273 $order_1_0 = C4::Acquisition::populate_order_with_prices(
283 got => $order_1_0->{rrp_tax_included},
286 field => 'rrp_tax_included'
291 got => $order_1_0->{rrp_tax_excluded},
294 field => 'rrp_tax_excluded'
299 got => $order_1_0->{ecost_tax_included},
302 field => 'ecost_tax_included'
307 got => $order_1_0->{ecost_tax_excluded},
310 field => 'ecost_tax_excluded'
315 got => $order_1_0->{tax_value_on_ordering},
322 $order_1_0 = C4::Acquisition::populate_order_with_prices(
332 got => $order_1_0->{unitprice_tax_included},
335 field => 'unitprice_tax_included'
340 got => $order_1_0->{unitprice_tax_excluded},
343 field => 'unitprice_tax_excluded'
348 got => $order_1_0->{tax_value_on_receiving},
356 subtest 'Configuration 1: 0 1' => sub {
359 my $biblionumber_0_1 = 45;
361 biblionumber => $biblionumber_0_1,
363 listprice => 82.000000,
364 unitprice => 77.490000,
365 quantityreceived => 2,
366 basketno => $basketno_1_1,
367 invoiceid => $invoiceid_1_1,
372 datereceived => $today
375 $order_0_1 = C4::Acquisition::populate_order_with_prices(
385 got => $order_0_1->{rrp_tax_included},
388 field => 'rrp_tax_included'
393 got => $order_0_1->{rrp_tax_excluded},
396 field => 'rrp_tax_excluded'
401 got => $order_0_1->{ecost_tax_included},
404 field => 'ecost_tax_included'
409 got => $order_0_1->{ecost_tax_excluded},
412 field => 'ecost_tax_excluded'
417 got => $order_0_1->{tax_value_on_ordering},
424 $order_0_1 = C4::Acquisition::populate_order_with_prices(
434 got => $order_0_1->{unitprice_tax_included},
437 field => 'unitprice_tax_included'
442 got => $order_0_1->{unitprice_tax_excluded},
445 field => 'unitprice_tax_excluded'
450 got => $order_0_1->{tax_value_on_receiving},
462 Koha::Number::Price->new( $params->{got} )->format,
463 Koha::Number::Price->new( $params->{expected} )->format,
464 "configuration $params->{conf}: $params->{field} should be correctly calculated"
469 for my $currency_format ( qw( US FR ) ) {
470 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
471 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
472 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );