2 use Test::More tests => 8;
9 use Koha::Number::Price;
13 t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
15 my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
17 my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
18 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
21 for my $currency_format ( qw( US FR ) ) {
22 t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
23 subtest 'Configuration 1: 0 0' => sub {
25 $bookseller_module->mock(
28 return { listincgst => 0, invoiceincgst => 0 };
32 my $biblionumber_0_0 = 42;
35 biblionumber => $biblionumber_0_0,
37 listprice => 82.000000,
38 unitprice => 73.80000,
39 quantityreceived => 2,
40 basketno => $basketno_0_0,
41 invoiceid => $invoiceid_0_0,
46 datereceived => $today
48 $order_0_0 = C4::Acquisition::populate_order_with_prices(
51 booksellerid => 'just_something',
56 # Note that this configuration is correct \o/
59 got => $order_0_0->{rrpgsti},
67 got => $order_0_0->{rrpgste},
75 got => $order_0_0->{ecostgsti},
83 got => $order_0_0->{ecostgste},
91 got => $order_0_0->{gstvalue},
99 got => $order_0_0->{totalgsti},
107 got => $order_0_0->{totalgste},
115 subtest 'Configuration 1: 1 1' => sub {
117 $bookseller_module->mock(
120 return { listincgst => 1, invoiceincgst => 1 };
124 my $biblionumber_1_1 = 43;
126 biblionumber => $biblionumber_1_1,
128 listprice => 82.000000,
129 unitprice => 73.800000,
130 quantityreceived => 2,
131 basketno => $basketno_1_1,
132 invoiceid => $invoiceid_1_1,
137 datereceived => $today
140 $order_1_1 = C4::Acquisition::populate_order_with_prices(
143 booksellerid => 'just_something',
148 # Note that this configuration is *not* correct
149 # gstvalue should be 7.03 instead of 7.02
152 got => $order_1_1->{rrpgsti},
160 got => $order_1_1->{rrpgste},
168 got => $order_1_1->{ecostgsti},
176 got => $order_1_1->{ecostgste},
184 got => $order_1_1->{gstvalue},
192 got => $order_1_1->{totalgsti},
200 got => $order_1_1->{totalgste},
208 subtest 'Configuration 1: 1 0' => sub {
210 $bookseller_module->mock(
213 return { listincgst => 1, invoiceincgst => 0 };
217 my $biblionumber_1_0 = 44;
219 biblionumber => $biblionumber_1_0,
221 listprice => 82.000000,
222 unitprice => 73.804500,
223 quantityreceived => 2,
224 basketno => $basketno_1_1,
225 invoiceid => $invoiceid_1_1,
230 datereceived => $today
233 $order_1_0 = C4::Acquisition::populate_order_with_prices(
236 booksellerid => 'just_something',
241 # Note that this configuration is *not* correct!
242 # rrp gsti should be 82 (what we inserted!)
243 # gstvalue should be 7.03 instead of 7.02
247 got => $order_1_0->{rrpgsti},
255 got => $order_1_0->{rrpgste},
263 got => $order_1_0->{ecostgsti},
271 got => $order_1_0->{ecostgste},
279 got => $order_1_0->{gstvalue},
287 got => $order_1_0->{totalgsti},
295 got => $order_1_0->{totalgste},
303 subtest 'Configuration 1: 0 1' => sub {
305 $bookseller_module->mock(
308 return { listincgst => 0, invoiceincgst => 1 };
312 my $biblionumber_0_1 = 45;
314 biblionumber => $biblionumber_0_1,
316 listprice => 82.000000,
317 unitprice => 73.800000,
318 quantityreceived => 2,
319 basketno => $basketno_1_1,
320 invoiceid => $invoiceid_1_1,
325 datereceived => $today
328 $order_0_1 = C4::Acquisition::populate_order_with_prices(
331 booksellerid => 'just_something',
336 # Note that this configuration is correct \o/
339 got => $order_0_1->{rrpgsti},
347 got => $order_0_1->{rrpgste},
355 got => $order_0_1->{ecostgsti},
363 got => $order_0_1->{ecostgste},
371 got => $order_0_1->{gstvalue},
379 got => $order_0_1->{totalgsti},
387 got => $order_0_1->{totalgste},
399 Koha::Number::Price->new( $params->{got} )->format,
400 Koha::Number::Price->new( $params->{expected} )->format,
401 "configuration $params->{conf}: $params->{field} should be correctly calculated"