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' => sub {
54 my $biblionumber_0_0 = 42;
57 biblionumber => $biblionumber_0_0,
59 listprice => 82.000000,
60 unitprice => 73.80000,
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' => sub {
156 my $biblionumber_1_1 = 43;
158 biblionumber => $biblionumber_1_1,
160 listprice => 82.000000,
161 unitprice => 73.800000,
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' => sub {
258 my $biblionumber_1_0 = 44;
260 biblionumber => $biblionumber_1_0,
262 listprice => 82.000000,
263 unitprice => 70.290000,
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'
316 got => $order_1_0->{tax_value_on_ordering},
323 $order_1_0 = C4::Acquisition::populate_order_with_prices(
333 got => $order_1_0->{unitprice_tax_included},
336 field => 'unitprice_tax_included'
341 got => $order_1_0->{unitprice_tax_excluded},
344 field => 'unitprice_tax_excluded'
349 got => $order_1_0->{tax_value_on_receiving},
357 subtest 'Configuration 1: 0 1' => sub {
360 my $biblionumber_0_1 = 45;
362 biblionumber => $biblionumber_0_1,
364 listprice => 82.000000,
365 unitprice => 77.490000,
366 quantityreceived => 2,
367 basketno => $basketno_1_1,
368 invoiceid => $invoiceid_1_1,
373 datereceived => $today
376 $order_0_1 = C4::Acquisition::populate_order_with_prices(
386 got => $order_0_1->{rrp_tax_included},
389 field => 'rrp_tax_included'
394 got => $order_0_1->{rrp_tax_excluded},
397 field => 'rrp_tax_excluded'
402 got => $order_0_1->{ecost_tax_included},
405 field => 'ecost_tax_included'
410 got => $order_0_1->{ecost_tax_excluded},
413 field => 'ecost_tax_excluded'
418 got => $order_0_1->{tax_value_on_ordering},
425 $order_0_1 = C4::Acquisition::populate_order_with_prices(
435 got => $order_0_1->{unitprice_tax_included},
438 field => 'unitprice_tax_included'
443 got => $order_0_1->{unitprice_tax_excluded},
446 field => 'unitprice_tax_excluded'
451 got => $order_0_1->{tax_value_on_receiving},
463 Koha::Number::Price->new( $params->{got} )->format,
464 Koha::Number::Price->new( $params->{expected} )->format,
465 "configuration $params->{conf}: $params->{field} should be correctly calculated"
470 for my $currency_format ( qw( US FR ) ) {
471 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
472 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
473 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );