2 use Test::More tests => 16;
8 my $context_module = t::lib::Mocks::mock_dbh;
9 use_ok('C4::Acquisition');
10 use_ok('C4::Bookseller');
11 use_ok('C4::Context');
12 use_ok('Koha::Number::Price');
15 t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
17 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
19 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
20 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
23 for my $currency_format ( qw( US FR ) ) {
24 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
25 subtest 'Configuration 1: 0 0' => sub {
27 $bookseller_module->mock(
30 return { listincgst => 0, invoiceincgst => 0 };
34 my $biblionumber_0_0 = 42;
37 biblionumber => $biblionumber_0_0,
39 listprice => 82.000000,
40 unitprice => 73.80000,
41 quantityreceived => 2,
42 basketno => $basketno_0_0,
43 invoiceid => $invoiceid_0_0,
48 datereceived => $today
50 $order_0_0 = C4::Acquisition::populate_order_with_prices(
53 booksellerid => 'just_something',
58 # Note that this configuration is correct \o/
61 got => $order_0_0->{rrpgsti},
69 got => $order_0_0->{rrpgste},
77 got => $order_0_0->{ecostgsti},
85 got => $order_0_0->{ecostgste},
93 got => $order_0_0->{gstvalue},
101 got => $order_0_0->{totalgsti},
109 got => $order_0_0->{totalgste},
117 subtest 'Configuration 1: 1 1' => sub {
119 $bookseller_module->mock(
122 return { listincgst => 1, invoiceincgst => 1 };
126 my $biblionumber_1_1 = 43;
128 biblionumber => $biblionumber_1_1,
130 listprice => 82.000000,
131 unitprice => 73.800000,
132 quantityreceived => 2,
133 basketno => $basketno_1_1,
134 invoiceid => $invoiceid_1_1,
139 datereceived => $today
142 $order_1_1 = C4::Acquisition::populate_order_with_prices(
145 booksellerid => 'just_something',
150 # Note that this configuration is *not* correct
151 # gstvalue should be 7.03 instead of 7.02
154 got => $order_1_1->{rrpgsti},
162 got => $order_1_1->{rrpgste},
170 got => $order_1_1->{ecostgsti},
178 got => $order_1_1->{ecostgste},
186 got => $order_1_1->{gstvalue},
194 got => $order_1_1->{totalgsti},
202 got => $order_1_1->{totalgste},
210 subtest 'Configuration 1: 1 0' => sub {
212 $bookseller_module->mock(
215 return { listincgst => 1, invoiceincgst => 0 };
219 my $biblionumber_1_0 = 44;
221 biblionumber => $biblionumber_1_0,
223 listprice => 82.000000,
224 unitprice => 73.804500,
225 quantityreceived => 2,
226 basketno => $basketno_1_1,
227 invoiceid => $invoiceid_1_1,
232 datereceived => $today
235 $order_1_0 = C4::Acquisition::populate_order_with_prices(
238 booksellerid => 'just_something',
243 # Note that this configuration is *not* correct!
244 # rrp gsti should be 82 (what we inserted!)
245 # gstvalue should be 7.03 instead of 7.02
249 got => $order_1_0->{rrpgsti},
257 got => $order_1_0->{rrpgste},
265 got => $order_1_0->{ecostgsti},
273 got => $order_1_0->{ecostgste},
281 got => $order_1_0->{gstvalue},
289 got => $order_1_0->{totalgsti},
297 got => $order_1_0->{totalgste},
305 subtest 'Configuration 1: 0 1' => sub {
307 $bookseller_module->mock(
310 return { listincgst => 0, invoiceincgst => 1 };
314 my $biblionumber_0_1 = 45;
316 biblionumber => $biblionumber_0_1,
318 listprice => 82.000000,
319 unitprice => 73.800000,
320 quantityreceived => 2,
321 basketno => $basketno_1_1,
322 invoiceid => $invoiceid_1_1,
327 datereceived => $today
330 $order_0_1 = C4::Acquisition::populate_order_with_prices(
333 booksellerid => 'just_something',
338 # Note that this configuration is correct \o/
341 got => $order_0_1->{rrpgsti},
349 got => $order_0_1->{rrpgste},
357 got => $order_0_1->{ecostgsti},
365 got => $order_0_1->{ecostgste},
373 got => $order_0_1->{gstvalue},
381 got => $order_0_1->{totalgsti},
389 got => $order_0_1->{totalgste},
401 Koha::Number::Price->new( $params->{got} )->format,
402 Koha::Number::Price->new( $params->{expected} )->format,
403 "configuration $params->{conf}: $params->{field} should be correctly calculated"
408 for my $currency_format ( qw( US FR ) ) {
409 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
410 is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
411 is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );