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 {
24 schema_class => 'Koha::Schema',
25 connect_info => ['dbi:SQLite:dbname=:memory:','',''],
26 connect_opts => { name_sep => '.', quote_char => '`', },
27 fixture_class => '::Populate',
30 my $db = Test::MockModule->new('Koha::Database');
31 $db->mock( _new_schema => sub { return Schema(); } );
35 [ qw/ currency symbol rate active / ],
36 [[ 'my_cur', '€', 1, 1, ]],
39 [ qw/ id name listincgst invoiceincgst / ],
45 ], 'add currency fixtures';
47 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
49 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
50 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
53 for my $currency_format ( qw( US FR ) ) {
54 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
55 subtest 'Configuration 1: 0 0' => sub {
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(
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(
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 {
160 my $biblionumber_1_1 = 43;
162 biblionumber => $biblionumber_1_1,
164 listprice => 82.000000,
165 unitprice => 73.800000,
166 quantityreceived => 2,
167 basketno => $basketno_1_1,
168 invoiceid => $invoiceid_1_1,
173 datereceived => $today
176 $order_1_1 = C4::Acquisition::populate_order_with_prices(
186 got => $order_1_1->{rrp_tax_included},
189 field => 'rrp_tax_included'
194 got => $order_1_1->{rrp_tax_excluded},
197 field => 'rrp_tax_excluded'
202 got => $order_1_1->{ecost_tax_included},
205 field => 'ecost_tax_included'
210 got => $order_1_1->{ecost_tax_excluded},
213 field => 'ecost_tax_excluded'
218 got => $order_1_1->{tax_value_on_ordering},
225 $order_1_1 = C4::Acquisition::populate_order_with_prices(
235 got => $order_1_1->{unitprice_tax_included},
238 field => 'unitprice_tax_included'
243 got => $order_1_1->{unitprice_tax_excluded},
246 field => 'unitprice_tax_excluded'
251 got => $order_1_1->{tax_value_on_receiving},
259 subtest 'Configuration 1: 1 0' => sub {
262 my $biblionumber_1_0 = 44;
264 biblionumber => $biblionumber_1_0,
266 listprice => 82.000000,
267 unitprice => 70.290000,
268 quantityreceived => 2,
269 basketno => $basketno_1_1,
270 invoiceid => $invoiceid_1_1,
275 datereceived => $today
278 $order_1_0 = C4::Acquisition::populate_order_with_prices(
288 got => $order_1_0->{rrp_tax_included},
291 field => 'rrp_tax_included'
296 got => $order_1_0->{rrp_tax_excluded},
299 field => 'rrp_tax_excluded'
304 got => $order_1_0->{ecost_tax_included},
307 field => 'ecost_tax_included'
312 got => $order_1_0->{ecost_tax_excluded},
315 field => 'ecost_tax_excluded'
320 got => $order_1_0->{tax_value_on_ordering},
327 $order_1_0 = C4::Acquisition::populate_order_with_prices(
337 got => $order_1_0->{unitprice_tax_included},
340 field => 'unitprice_tax_included'
345 got => $order_1_0->{unitprice_tax_excluded},
348 field => 'unitprice_tax_excluded'
353 got => $order_1_0->{tax_value_on_receiving},
361 subtest 'Configuration 1: 0 1' => sub {
364 my $biblionumber_0_1 = 45;
366 biblionumber => $biblionumber_0_1,
368 listprice => 82.000000,
369 unitprice => 77.490000,
370 quantityreceived => 2,
371 basketno => $basketno_1_1,
372 invoiceid => $invoiceid_1_1,
377 datereceived => $today
380 $order_0_1 = C4::Acquisition::populate_order_with_prices(
390 got => $order_0_1->{rrp_tax_included},
393 field => 'rrp_tax_included'
398 got => $order_0_1->{rrp_tax_excluded},
401 field => 'rrp_tax_excluded'
406 got => $order_0_1->{ecost_tax_included},
409 field => 'ecost_tax_included'
414 got => $order_0_1->{ecost_tax_excluded},
417 field => 'ecost_tax_excluded'
422 got => $order_0_1->{tax_value_on_ordering},
429 $order_0_1 = C4::Acquisition::populate_order_with_prices(
439 got => $order_0_1->{unitprice_tax_included},
442 field => 'unitprice_tax_included'
447 got => $order_0_1->{unitprice_tax_excluded},
450 field => 'unitprice_tax_excluded'
455 got => $order_0_1->{tax_value_on_receiving},
467 Koha::Number::Price->new( $params->{got} )->format,
468 Koha::Number::Price->new( $params->{expected} )->format,
469 "configuration $params->{conf}: $params->{field} should be correctly calculated"
474 for my $currency_format ( qw( US FR ) ) {
475 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
476 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
477 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );