Lines 1-509
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
1 |
use Modern::Perl; |
3 |
use Modern::Perl; |
2 |
use Test::More; |
4 |
use Test::More tests => 1; |
3 |
use Test::MockModule; |
5 |
use Test::MockModule; |
4 |
|
6 |
|
5 |
use t::lib::Mocks; |
7 |
use t::lib::Mocks; |
|
|
8 |
use t::lib::TestBuilder; |
6 |
|
9 |
|
7 |
use Module::Load::Conditional qw/check_install/; |
10 |
use Koha::Database; |
|
|
11 |
use Koha::Number::Price; |
8 |
|
12 |
|
9 |
BEGIN { |
13 |
my $schema = Koha::Database->new->schema; |
10 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
14 |
$schema->storage->txn_begin; |
11 |
plan tests => 15; |
15 |
my $builder = t::lib::TestBuilder->new; |
12 |
} else { |
|
|
13 |
plan skip_all => "Need Test::DBIx::Class" |
14 |
} |
15 |
} |
16 |
|
17 |
use_ok('C4::Context'); |
18 |
use_ok('Koha::Number::Price'); |
19 |
|
20 |
t::lib::Mocks::mock_preference( 'TaxRates', '0.02|0.05|0.196' ); |
21 |
|
22 |
use Test::DBIx::Class; |
23 |
|
24 |
my $db = Test::MockModule->new('Koha::Database'); |
25 |
$db->mock( _new_schema => sub { return Schema(); } ); |
26 |
Koha::Database::flush_schema_cache(); |
27 |
|
28 |
fixtures_ok [ |
29 |
Currency => [ |
30 |
[ qw/ currency symbol rate active / ], |
31 |
[ 'my_cur', '€', 1, 1, ], |
32 |
], |
33 |
Aqbookseller => [ |
34 |
[ qw/ id name listincgst invoiceincgst / ], |
35 |
[ 1, '0 0', 0, 0 ], |
36 |
[ 2, '0 1', 0, 1 ], |
37 |
[ 3, '1 0', 1, 0 ], |
38 |
[ 4, '1 1', 1, 1 ], |
39 |
], |
40 |
Aqbasket => [ |
41 |
[ qw/ basketno basketname booksellerid / ], |
42 |
[ 1, '0 0', 1 ], |
43 |
[ 2, '0 1', 2 ], |
44 |
[ 3, '1 0', 3 ], |
45 |
[ 4, '1 1', 4 ], |
46 |
], |
47 |
], 'add currency fixtures'; |
48 |
|
49 |
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller'); |
50 |
|
51 |
my ( $basketno_0_0, $basketno_0_1, $basketno_1_0, $basketno_1_1 ) = (1, 2, 3, 4); |
52 |
my ( $invoiceid_0_0, $invoiceid_1_1 ); |
53 |
my $today; |
54 |
|
55 |
for my $currency_format ( qw( US FR ) ) { |
56 |
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); |
57 |
subtest 'Configuration 1: 0 0 (Vendor List prices do not include tax / Invoice prices do not include tax)' => sub { |
58 |
plan tests => 8; |
59 |
|
60 |
my $biblionumber_0_0 = 42; |
61 |
|
62 |
my $order_0_0 = Koha::Acquisition::Order->new({ |
63 |
biblionumber => $biblionumber_0_0, |
64 |
quantity => 2, |
65 |
listprice => 82, |
66 |
unitprice => 73.80, |
67 |
quantityreceived => 2, |
68 |
basketno => $basketno_0_0, |
69 |
invoiceid => $invoiceid_0_0, |
70 |
rrp => 82.00, |
71 |
ecost => 73.80, |
72 |
tax_rate_on_ordering => 0.0500, |
73 |
tax_rate_on_receiving => 0.0500, |
74 |
discount => 10, |
75 |
datereceived => $today |
76 |
}); |
77 |
$order_0_0->populate_with_prices_for_ordering(); |
78 |
|
79 |
compare( |
80 |
{ |
81 |
got => $order_0_0->rrp_tax_included, |
82 |
expected => 86.10, |
83 |
conf => '0 0', |
84 |
field => 'rrp_tax_included' |
85 |
} |
86 |
); |
87 |
compare( |
88 |
{ |
89 |
got => $order_0_0->rrp_tax_excluded, |
90 |
expected => 82.00, |
91 |
conf => '0 0', |
92 |
field => 'rrp_tax_excluded' |
93 |
} |
94 |
); |
95 |
compare( |
96 |
{ |
97 |
got => $order_0_0->ecost_tax_included, |
98 |
expected => 77.49, |
99 |
conf => '0 0', |
100 |
field => 'ecost_tax_included' |
101 |
} |
102 |
); |
103 |
compare( |
104 |
{ |
105 |
got => $order_0_0->ecost_tax_excluded, |
106 |
expected => 73.80, |
107 |
conf => '0 0', |
108 |
field => 'ecost_tax_excluded' |
109 |
} |
110 |
); |
111 |
compare( |
112 |
{ |
113 |
got => $order_0_0->tax_value_on_ordering, |
114 |
expected => 7.38, |
115 |
conf => '0 0', |
116 |
field => 'tax_value' |
117 |
} |
118 |
); |
119 |
|
16 |
|
120 |
$order_0_0->populate_with_prices_for_receiving(); |
17 |
subtest 'Tests from t' => sub { |
|
|
18 |
plan tests => 12; |
121 |
|
19 |
|
122 |
compare( |
20 |
t::lib::Mocks::mock_preference( 'TaxRates', '0.02|0.05|0.196' ); |
123 |
{ |
21 |
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller'); |
124 |
got => $order_0_0->unitprice_tax_included, |
|
|
125 |
expected => 77.49, |
126 |
conf => '0 0', |
127 |
field => 'unitprice_tax_included' |
128 |
} |
129 |
); |
130 |
compare( |
131 |
{ |
132 |
got => $order_0_0->unitprice_tax_excluded, |
133 |
expected => 73.80, |
134 |
conf => '0 0', |
135 |
field => 'unitprice_tax_excluded' |
136 |
} |
137 |
); |
138 |
compare( |
139 |
{ |
140 |
got => $order_0_0->tax_value_on_receiving, |
141 |
expected => 7.38, |
142 |
conf => '0 0', |
143 |
field => 'tax_value' |
144 |
} |
145 |
); |
146 |
}; |
147 |
|
148 |
subtest 'Configuration 1: 1 1 (Vendor List prices do include tax / Invoice prices include tax)' => sub { |
149 |
plan tests => 11; |
150 |
|
151 |
my $biblionumber_1_1 = 43; |
152 |
my $order_1_1 = Koha::Acquisition::Order->new({ |
153 |
biblionumber => $biblionumber_1_1, |
154 |
quantity => 2, |
155 |
listprice => 82, |
156 |
unitprice => 73.80, |
157 |
quantityreceived => 2, |
158 |
basketno => $basketno_1_1, |
159 |
invoiceid => $invoiceid_1_1, |
160 |
rrp => 82.00, |
161 |
ecost => 73.80, |
162 |
tax_rate_on_ordering => 0.0500, |
163 |
tax_rate_on_receiving => 0.0500, |
164 |
discount => 10, |
165 |
datereceived => $today |
166 |
}); |
167 |
|
168 |
$order_1_1->populate_with_prices_for_ordering(); |
169 |
|
170 |
compare( |
171 |
{ |
172 |
got => $order_1_1->rrp_tax_included, |
173 |
expected => 82.00, |
174 |
conf => '1 1', |
175 |
field => 'rrp_tax_included' |
176 |
} |
177 |
); |
178 |
compare( |
179 |
{ |
180 |
got => $order_1_1->rrp_tax_excluded, |
181 |
expected => 78.10, |
182 |
conf => '1 1', |
183 |
field => 'rrp_tax_excluded' |
184 |
} |
185 |
); |
186 |
compare( |
187 |
{ |
188 |
got => $order_1_1->ecost_tax_included, |
189 |
expected => 73.80, |
190 |
conf => '1 1', |
191 |
field => 'ecost_tax_included' |
192 |
} |
193 |
); |
194 |
compare( |
195 |
{ |
196 |
got => $order_1_1->ecost_tax_excluded, |
197 |
expected => 70.29, |
198 |
conf => '1 1', |
199 |
field => 'ecost_tax_excluded' |
200 |
} |
201 |
); |
202 |
compare( |
203 |
{ |
204 |
got => $order_1_1->tax_value_on_ordering, |
205 |
expected => 7.03, |
206 |
conf => '1 1', |
207 |
field => 'tax_value' |
208 |
} |
209 |
); |
210 |
|
211 |
$order_1_1->populate_with_prices_for_receiving(); |
212 |
|
213 |
compare( |
214 |
{ |
215 |
got => $order_1_1->unitprice_tax_included, |
216 |
expected => 73.80, |
217 |
conf => '1 1', |
218 |
field => 'unitprice_tax_included' |
219 |
} |
220 |
); |
221 |
compare( |
222 |
{ |
223 |
got => $order_1_1->unitprice_tax_excluded, |
224 |
expected => 70.29, |
225 |
conf => '1 1', |
226 |
field => 'unitprice_tax_excluded' |
227 |
} |
228 |
); |
229 |
compare( |
230 |
{ |
231 |
got => $order_1_1->tax_value_on_receiving, |
232 |
expected => 7.03, |
233 |
conf => '1 1', |
234 |
field => 'tax_value' |
235 |
} |
236 |
); |
237 |
|
22 |
|
238 |
# When unitprice is 0.00 |
23 |
my ( @booksellers, @baskets ); |
239 |
# Koha::Acquisition::Order::populate_with_prices_for_ordering() falls |
24 |
my @names = ( '0 0', '0 1', '1 0', '1 1' ); |
240 |
# back to using ecost_tax_included and ecost_tax_excluded |
25 |
foreach my $i ( 1..4 ) { |
241 |
$order_1_1 = Koha::Acquisition::Order->new({ |
26 |
push @booksellers, $builder->build_object( |
242 |
biblionumber => $biblionumber_1_1, |
|
|
243 |
quantity => 1, |
244 |
listprice => 10, |
245 |
unitprice => '0.00', |
246 |
quantityreceived => 1, |
247 |
basketno => $basketno_1_1, |
248 |
invoiceid => $invoiceid_1_1, |
249 |
rrp => 10.00, |
250 |
ecost => 10.00, |
251 |
tax_rate_on_ordering => 0.1500, |
252 |
tax_rate_on_receiving => 0.1500, |
253 |
discount => 0, |
254 |
datereceived => $today |
255 |
}); |
256 |
|
257 |
$order_1_1->populate_with_prices_for_ordering(); |
258 |
|
259 |
compare( |
260 |
{ |
27 |
{ |
261 |
got => $order_1_1->ecost_tax_included, |
28 |
class => 'Koha::Acquisition::Booksellers', |
262 |
expected => 10.00, |
29 |
value => |
263 |
conf => '1 1', |
30 |
{ name => $names[ $i - 1 ], listincgst => $i < 3 ? 0 : 1, invoiceincgst => $i % 2 == 0 ? 1 : 0 } |
264 |
field => 'ecost_tax_included' |
|
|
265 |
} |
31 |
} |
266 |
); |
32 |
); |
267 |
compare( |
33 |
push @baskets, $builder->build_object( |
268 |
{ |
34 |
{ |
269 |
got => $order_1_1->ecost_tax_excluded, |
35 |
class => 'Koha::Acquisition::Baskets', |
270 |
expected => 8.70, |
36 |
value => |
271 |
conf => '1 1', |
37 |
{ basketname => $names[ $i - 1 ], booksellerid => $booksellers[$i-1]->id } |
272 |
field => 'ecost_tax_excluded' |
|
|
273 |
} |
274 |
); |
275 |
compare( |
276 |
{ |
277 |
got => $order_1_1->tax_value_on_ordering, |
278 |
expected => 1.30, |
279 |
conf => '1 1', |
280 |
field => 'tax_value' |
281 |
} |
282 |
); |
283 |
}; |
284 |
|
285 |
subtest 'Configuration 1: 1 0 (Vendor List prices include tax / Invoice prices do not include tax)' => sub { |
286 |
plan tests => 9; |
287 |
|
288 |
my $biblionumber_1_0 = 44; |
289 |
my $order_1_0 = Koha::Acquisition::Order->new({ |
290 |
biblionumber => $biblionumber_1_0, |
291 |
quantity => 2, |
292 |
listprice => 82, |
293 |
unitprice => 0, |
294 |
quantityreceived => 2, |
295 |
basketno => $basketno_1_0, |
296 |
invoiceid => $invoiceid_1_1, |
297 |
rrp => 82.00, |
298 |
ecost => 73.80, |
299 |
tax_rate_on_ordering => 0.0500, |
300 |
tax_rate_on_receiving => 0.0500, |
301 |
discount => 10, |
302 |
datereceived => $today |
303 |
}); |
304 |
|
305 |
$order_1_0->populate_with_prices_for_ordering(); |
306 |
|
307 |
compare( |
308 |
{ |
309 |
got => $order_1_0->rrp_tax_included, |
310 |
expected => 82, |
311 |
conf => '1 0', |
312 |
field => 'rrp_tax_included' |
313 |
} |
314 |
); |
315 |
compare( |
316 |
{ |
317 |
got => $order_1_0->rrp_tax_excluded, |
318 |
expected => 78.10, |
319 |
conf => '1 0', |
320 |
field => 'rrp_tax_excluded' |
321 |
} |
322 |
); |
323 |
compare( |
324 |
{ |
325 |
got => $order_1_0->ecost_tax_included, |
326 |
expected => 73.80, |
327 |
conf => '1 0', |
328 |
field => 'ecost_tax_included' |
329 |
} |
330 |
); |
331 |
compare( |
332 |
{ |
333 |
got => $order_1_0->ecost_tax_excluded, |
334 |
expected => 70.29, |
335 |
conf => '1 0', |
336 |
field => 'ecost_tax_excluded' |
337 |
} |
338 |
); |
339 |
# If we order with unitprice = 0, tax is calculated from the ecost |
340 |
# (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost |
341 |
compare( |
342 |
{ |
343 |
got => $order_1_0->tax_value_on_ordering, |
344 |
expected => 7.03, |
345 |
conf => '1 0', |
346 |
field => 'tax_value' |
347 |
} |
348 |
); |
349 |
$order_1_0->unitprice(70.29); |
350 |
$order_1_0->populate_with_prices_for_ordering(); |
351 |
|
352 |
# If a unitprice is provided at ordering, we calculate the tax from that |
353 |
compare( |
354 |
{ |
355 |
got => $order_1_0->tax_value_on_ordering, |
356 |
expected => 6.69, |
357 |
conf => '1 0', |
358 |
field => 'tax_value' |
359 |
} |
38 |
} |
360 |
); |
39 |
); |
|
|
40 |
} |
361 |
|
41 |
|
362 |
$order_1_0->populate_with_prices_for_receiving(); |
42 |
my ( $basketno_0_0, $basketno_0_1, $basketno_1_0, $basketno_1_1 ) = map { $_->id } @baskets; |
|
|
43 |
my ( $invoiceid_0_0, $invoiceid_1_1 ); |
44 |
my $today; |
45 |
|
46 |
for my $currency_format ( qw( US FR ) ) { |
47 |
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); |
48 |
subtest 'Configuration 1: 0 0 (Vendor List prices do not include tax / Invoice prices do not include tax)' => sub { |
49 |
plan tests => 8; |
50 |
|
51 |
my $biblionumber_0_0 = 42; |
52 |
|
53 |
my $order_0_0 = Koha::Acquisition::Order->new({ |
54 |
biblionumber => $biblionumber_0_0, |
55 |
quantity => 2, |
56 |
listprice => 82, |
57 |
unitprice => 73.80, |
58 |
quantityreceived => 2, |
59 |
basketno => $basketno_0_0, |
60 |
invoiceid => $invoiceid_0_0, |
61 |
rrp => 82.00, |
62 |
ecost => 73.80, |
63 |
tax_rate_on_ordering => 0.0500, |
64 |
tax_rate_on_receiving => 0.0500, |
65 |
discount => 10, |
66 |
datereceived => $today |
67 |
}); |
68 |
$order_0_0->populate_with_prices_for_ordering(); |
69 |
|
70 |
compare( |
71 |
{ |
72 |
got => $order_0_0->rrp_tax_included, |
73 |
expected => 86.10, |
74 |
conf => '0 0', |
75 |
field => 'rrp_tax_included' |
76 |
} |
77 |
); |
78 |
compare( |
79 |
{ |
80 |
got => $order_0_0->rrp_tax_excluded, |
81 |
expected => 82.00, |
82 |
conf => '0 0', |
83 |
field => 'rrp_tax_excluded' |
84 |
} |
85 |
); |
86 |
compare( |
87 |
{ |
88 |
got => $order_0_0->ecost_tax_included, |
89 |
expected => 77.49, |
90 |
conf => '0 0', |
91 |
field => 'ecost_tax_included' |
92 |
} |
93 |
); |
94 |
compare( |
95 |
{ |
96 |
got => $order_0_0->ecost_tax_excluded, |
97 |
expected => 73.80, |
98 |
conf => '0 0', |
99 |
field => 'ecost_tax_excluded' |
100 |
} |
101 |
); |
102 |
compare( |
103 |
{ |
104 |
got => $order_0_0->tax_value_on_ordering, |
105 |
expected => 7.38, |
106 |
conf => '0 0', |
107 |
field => 'tax_value' |
108 |
} |
109 |
); |
110 |
|
111 |
$order_0_0->populate_with_prices_for_receiving(); |
112 |
|
113 |
compare( |
114 |
{ |
115 |
got => $order_0_0->unitprice_tax_included, |
116 |
expected => 77.49, |
117 |
conf => '0 0', |
118 |
field => 'unitprice_tax_included' |
119 |
} |
120 |
); |
121 |
compare( |
122 |
{ |
123 |
got => $order_0_0->unitprice_tax_excluded, |
124 |
expected => 73.80, |
125 |
conf => '0 0', |
126 |
field => 'unitprice_tax_excluded' |
127 |
} |
128 |
); |
129 |
compare( |
130 |
{ |
131 |
got => $order_0_0->tax_value_on_receiving, |
132 |
expected => 7.38, |
133 |
conf => '0 0', |
134 |
field => 'tax_value' |
135 |
} |
136 |
); |
137 |
}; |
138 |
|
139 |
subtest 'Configuration 1: 1 1 (Vendor List prices do include tax / Invoice prices include tax)' => sub { |
140 |
plan tests => 11; |
141 |
|
142 |
my $biblionumber_1_1 = 43; |
143 |
my $order_1_1 = Koha::Acquisition::Order->new({ |
144 |
biblionumber => $biblionumber_1_1, |
145 |
quantity => 2, |
146 |
listprice => 82, |
147 |
unitprice => 73.80, |
148 |
quantityreceived => 2, |
149 |
basketno => $basketno_1_1, |
150 |
invoiceid => $invoiceid_1_1, |
151 |
rrp => 82.00, |
152 |
ecost => 73.80, |
153 |
tax_rate_on_ordering => 0.0500, |
154 |
tax_rate_on_receiving => 0.0500, |
155 |
discount => 10, |
156 |
datereceived => $today |
157 |
}); |
158 |
|
159 |
$order_1_1->populate_with_prices_for_ordering(); |
160 |
|
161 |
compare( |
162 |
{ |
163 |
got => $order_1_1->rrp_tax_included, |
164 |
expected => 82.00, |
165 |
conf => '1 1', |
166 |
field => 'rrp_tax_included' |
167 |
} |
168 |
); |
169 |
compare( |
170 |
{ |
171 |
got => $order_1_1->rrp_tax_excluded, |
172 |
expected => 78.10, |
173 |
conf => '1 1', |
174 |
field => 'rrp_tax_excluded' |
175 |
} |
176 |
); |
177 |
compare( |
178 |
{ |
179 |
got => $order_1_1->ecost_tax_included, |
180 |
expected => 73.80, |
181 |
conf => '1 1', |
182 |
field => 'ecost_tax_included' |
183 |
} |
184 |
); |
185 |
compare( |
186 |
{ |
187 |
got => $order_1_1->ecost_tax_excluded, |
188 |
expected => 70.29, |
189 |
conf => '1 1', |
190 |
field => 'ecost_tax_excluded' |
191 |
} |
192 |
); |
193 |
compare( |
194 |
{ |
195 |
got => $order_1_1->tax_value_on_ordering, |
196 |
expected => 7.03, |
197 |
conf => '1 1', |
198 |
field => 'tax_value' |
199 |
} |
200 |
); |
201 |
|
202 |
$order_1_1->populate_with_prices_for_receiving(); |
203 |
|
204 |
compare( |
205 |
{ |
206 |
got => $order_1_1->unitprice_tax_included, |
207 |
expected => 73.80, |
208 |
conf => '1 1', |
209 |
field => 'unitprice_tax_included' |
210 |
} |
211 |
); |
212 |
compare( |
213 |
{ |
214 |
got => $order_1_1->unitprice_tax_excluded, |
215 |
expected => 70.29, |
216 |
conf => '1 1', |
217 |
field => 'unitprice_tax_excluded' |
218 |
} |
219 |
); |
220 |
compare( |
221 |
{ |
222 |
got => $order_1_1->tax_value_on_receiving, |
223 |
expected => 7.03, |
224 |
conf => '1 1', |
225 |
field => 'tax_value' |
226 |
} |
227 |
); |
228 |
|
229 |
# When unitprice is 0.00 |
230 |
# Koha::Acquisition::Order::populate_with_prices_for_ordering() falls |
231 |
# back to using ecost_tax_included and ecost_tax_excluded |
232 |
$order_1_1 = Koha::Acquisition::Order->new({ |
233 |
biblionumber => $biblionumber_1_1, |
234 |
quantity => 1, |
235 |
listprice => 10, |
236 |
unitprice => '0.00', |
237 |
quantityreceived => 1, |
238 |
basketno => $basketno_1_1, |
239 |
invoiceid => $invoiceid_1_1, |
240 |
rrp => 10.00, |
241 |
ecost => 10.00, |
242 |
tax_rate_on_ordering => 0.1500, |
243 |
tax_rate_on_receiving => 0.1500, |
244 |
discount => 0, |
245 |
datereceived => $today |
246 |
}); |
247 |
|
248 |
$order_1_1->populate_with_prices_for_ordering(); |
249 |
|
250 |
compare( |
251 |
{ |
252 |
got => $order_1_1->ecost_tax_included, |
253 |
expected => 10.00, |
254 |
conf => '1 1', |
255 |
field => 'ecost_tax_included' |
256 |
} |
257 |
); |
258 |
compare( |
259 |
{ |
260 |
got => $order_1_1->ecost_tax_excluded, |
261 |
expected => 8.70, |
262 |
conf => '1 1', |
263 |
field => 'ecost_tax_excluded' |
264 |
} |
265 |
); |
266 |
compare( |
267 |
{ |
268 |
got => $order_1_1->tax_value_on_ordering, |
269 |
expected => 1.30, |
270 |
conf => '1 1', |
271 |
field => 'tax_value' |
272 |
} |
273 |
); |
274 |
}; |
275 |
|
276 |
subtest 'Configuration 1: 1 0 (Vendor List prices include tax / Invoice prices do not include tax)' => sub { |
277 |
plan tests => 9; |
278 |
|
279 |
my $biblionumber_1_0 = 44; |
280 |
my $order_1_0 = Koha::Acquisition::Order->new({ |
281 |
biblionumber => $biblionumber_1_0, |
282 |
quantity => 2, |
283 |
listprice => 82, |
284 |
unitprice => 0, |
285 |
quantityreceived => 2, |
286 |
basketno => $basketno_1_0, |
287 |
invoiceid => $invoiceid_1_1, |
288 |
rrp => 82.00, |
289 |
ecost => 73.80, |
290 |
tax_rate_on_ordering => 0.0500, |
291 |
tax_rate_on_receiving => 0.0500, |
292 |
discount => 10, |
293 |
datereceived => $today |
294 |
}); |
295 |
|
296 |
$order_1_0->populate_with_prices_for_ordering(); |
297 |
|
298 |
compare( |
299 |
{ |
300 |
got => $order_1_0->rrp_tax_included, |
301 |
expected => 82, |
302 |
conf => '1 0', |
303 |
field => 'rrp_tax_included' |
304 |
} |
305 |
); |
306 |
compare( |
307 |
{ |
308 |
got => $order_1_0->rrp_tax_excluded, |
309 |
expected => 78.10, |
310 |
conf => '1 0', |
311 |
field => 'rrp_tax_excluded' |
312 |
} |
313 |
); |
314 |
compare( |
315 |
{ |
316 |
got => $order_1_0->ecost_tax_included, |
317 |
expected => 73.80, |
318 |
conf => '1 0', |
319 |
field => 'ecost_tax_included' |
320 |
} |
321 |
); |
322 |
compare( |
323 |
{ |
324 |
got => $order_1_0->ecost_tax_excluded, |
325 |
expected => 70.29, |
326 |
conf => '1 0', |
327 |
field => 'ecost_tax_excluded' |
328 |
} |
329 |
); |
330 |
# If we order with unitprice = 0, tax is calculated from the ecost |
331 |
# (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost |
332 |
compare( |
333 |
{ |
334 |
got => $order_1_0->tax_value_on_ordering, |
335 |
expected => 7.03, |
336 |
conf => '1 0', |
337 |
field => 'tax_value' |
338 |
} |
339 |
); |
340 |
$order_1_0->unitprice(70.29); |
341 |
$order_1_0->populate_with_prices_for_ordering(); |
342 |
|
343 |
# If a unitprice is provided at ordering, we calculate the tax from that |
344 |
compare( |
345 |
{ |
346 |
got => $order_1_0->tax_value_on_ordering, |
347 |
expected => 6.69, |
348 |
conf => '1 0', |
349 |
field => 'tax_value' |
350 |
} |
351 |
); |
352 |
|
353 |
$order_1_0->populate_with_prices_for_receiving(); |
354 |
|
355 |
compare( |
356 |
{ |
357 |
got => $order_1_0->unitprice_tax_included, |
358 |
expected => 73.80, |
359 |
conf => '1 0', |
360 |
field => 'unitprice_tax_included' |
361 |
} |
362 |
); |
363 |
compare( |
364 |
{ |
365 |
got => $order_1_0->unitprice_tax_excluded, |
366 |
expected => 70.29, |
367 |
conf => '1 0', |
368 |
field => 'unitprice_tax_excluded' |
369 |
} |
370 |
); |
371 |
compare( |
372 |
{ |
373 |
got => $order_1_0->tax_value_on_receiving, |
374 |
expected => 7.03, |
375 |
conf => '1 0', |
376 |
field => 'tax_value' |
377 |
} |
378 |
); |
379 |
}; |
380 |
|
381 |
subtest 'Configuration 1: 0 1 (Vendor List prices do not include tax / Invoice prices include tax)' => sub { |
382 |
plan tests => 9; |
383 |
|
384 |
my $biblionumber_0_1 = 45; |
385 |
my $order_0_1 = Koha::Acquisition::Order->new({ |
386 |
biblionumber => $biblionumber_0_1, |
387 |
quantity => 2, |
388 |
listprice => 82, |
389 |
unitprice => 0, |
390 |
quantityreceived => 2, |
391 |
basketno => $basketno_0_1, |
392 |
invoiceid => $invoiceid_1_1, |
393 |
rrp => 82.00, |
394 |
ecost => 73.80, |
395 |
tax_rate_on_ordering => 0.0500, |
396 |
tax_rate_on_receiving => 0.0500, |
397 |
discount => 10, |
398 |
datereceived => $today |
399 |
}); |
400 |
|
401 |
$order_0_1->populate_with_prices_for_ordering(); |
402 |
|
403 |
compare( |
404 |
{ |
405 |
got => $order_0_1->rrp_tax_included, |
406 |
expected => 86.10, |
407 |
conf => '0 1', |
408 |
field => 'rrp_tax_included' |
409 |
} |
410 |
); |
411 |
compare( |
412 |
{ |
413 |
got => $order_0_1->rrp_tax_excluded, |
414 |
expected => 82.00, |
415 |
conf => '0 1', |
416 |
field => 'rrp_tax_excluded' |
417 |
} |
418 |
); |
419 |
compare( |
420 |
{ |
421 |
got => $order_0_1->ecost_tax_included, |
422 |
expected => 77.49, |
423 |
conf => '0 1', |
424 |
field => 'ecost_tax_included' |
425 |
} |
426 |
); |
427 |
compare( |
428 |
{ |
429 |
got => $order_0_1->ecost_tax_excluded, |
430 |
expected => 73.80, |
431 |
conf => '0 1', |
432 |
field => 'ecost_tax_excluded' |
433 |
} |
434 |
); |
435 |
# If we order with unitprice = 0, tax is calculated from the ecost |
436 |
# (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost |
437 |
compare( |
438 |
{ |
439 |
got => $order_0_1->tax_value_on_ordering, |
440 |
expected => 7.38, |
441 |
conf => '0 1', |
442 |
field => 'tax_value' |
443 |
} |
444 |
); |
445 |
$order_0_1->unitprice(77.490000); |
446 |
$order_0_1->populate_with_prices_for_ordering(); |
447 |
|
448 |
# If a unitprice is provided at ordering, we calculate the tax from that |
449 |
compare( |
450 |
{ |
451 |
got => $order_0_1->tax_value_on_ordering, |
452 |
expected => 7.75, |
453 |
conf => '0 1', |
454 |
field => 'tax_value' |
455 |
} |
456 |
); |
457 |
$order_0_1->populate_with_prices_for_receiving(); |
458 |
|
459 |
compare( |
460 |
{ |
461 |
got => $order_0_1->unitprice_tax_included, |
462 |
expected => 77.49, |
463 |
conf => '0 1', |
464 |
field => 'unitprice_tax_included' |
465 |
} |
466 |
); |
467 |
compare( |
468 |
{ |
469 |
got => $order_0_1->unitprice_tax_excluded, |
470 |
expected => 73.80, |
471 |
conf => '0 1', |
472 |
field => 'unitprice_tax_excluded' |
473 |
} |
474 |
); |
475 |
compare( |
476 |
{ |
477 |
got => $order_0_1->tax_value_on_receiving, |
478 |
expected => 7.38, |
479 |
conf => '0 1', |
480 |
field => 'tax_value' |
481 |
} |
482 |
); |
483 |
}; |
484 |
} |
363 |
|
485 |
|
364 |
compare( |
486 |
sub compare { |
365 |
{ |
487 |
my ($params) = @_; |
366 |
got => $order_1_0->unitprice_tax_included, |
488 |
is( |
367 |
expected => 73.80, |
489 |
Koha::Number::Price->new( $params->{got} )->format, |
368 |
conf => '1 0', |
490 |
Koha::Number::Price->new( $params->{expected} )->format, |
369 |
field => 'unitprice_tax_included' |
491 |
"configuration $params->{conf}: $params->{field} should be correctly calculated" |
370 |
} |
|
|
371 |
); |
372 |
compare( |
373 |
{ |
374 |
got => $order_1_0->unitprice_tax_excluded, |
375 |
expected => 70.29, |
376 |
conf => '1 0', |
377 |
field => 'unitprice_tax_excluded' |
378 |
} |
379 |
); |
380 |
compare( |
381 |
{ |
382 |
got => $order_1_0->tax_value_on_receiving, |
383 |
expected => 7.03, |
384 |
conf => '1 0', |
385 |
field => 'tax_value' |
386 |
} |
387 |
); |
388 |
}; |
389 |
|
390 |
subtest 'Configuration 1: 0 1 (Vendor List prices do not include tax / Invoice prices include tax)' => sub { |
391 |
plan tests => 9; |
392 |
|
393 |
my $biblionumber_0_1 = 45; |
394 |
my $order_0_1 = Koha::Acquisition::Order->new({ |
395 |
biblionumber => $biblionumber_0_1, |
396 |
quantity => 2, |
397 |
listprice => 82, |
398 |
unitprice => 0, |
399 |
quantityreceived => 2, |
400 |
basketno => $basketno_0_1, |
401 |
invoiceid => $invoiceid_1_1, |
402 |
rrp => 82.00, |
403 |
ecost => 73.80, |
404 |
tax_rate_on_ordering => 0.0500, |
405 |
tax_rate_on_receiving => 0.0500, |
406 |
discount => 10, |
407 |
datereceived => $today |
408 |
}); |
409 |
|
410 |
$order_0_1->populate_with_prices_for_ordering(); |
411 |
|
412 |
compare( |
413 |
{ |
414 |
got => $order_0_1->rrp_tax_included, |
415 |
expected => 86.10, |
416 |
conf => '0 1', |
417 |
field => 'rrp_tax_included' |
418 |
} |
419 |
); |
420 |
compare( |
421 |
{ |
422 |
got => $order_0_1->rrp_tax_excluded, |
423 |
expected => 82.00, |
424 |
conf => '0 1', |
425 |
field => 'rrp_tax_excluded' |
426 |
} |
427 |
); |
428 |
compare( |
429 |
{ |
430 |
got => $order_0_1->ecost_tax_included, |
431 |
expected => 77.49, |
432 |
conf => '0 1', |
433 |
field => 'ecost_tax_included' |
434 |
} |
435 |
); |
436 |
compare( |
437 |
{ |
438 |
got => $order_0_1->ecost_tax_excluded, |
439 |
expected => 73.80, |
440 |
conf => '0 1', |
441 |
field => 'ecost_tax_excluded' |
442 |
} |
443 |
); |
444 |
# If we order with unitprice = 0, tax is calculated from the ecost |
445 |
# (note that in addorder.pl and addorderiso2709 the unitprice may/will be set to the ecost |
446 |
compare( |
447 |
{ |
448 |
got => $order_0_1->tax_value_on_ordering, |
449 |
expected => 7.38, |
450 |
conf => '0 1', |
451 |
field => 'tax_value' |
452 |
} |
453 |
); |
492 |
); |
454 |
$order_0_1->unitprice(77.490000); |
493 |
} |
455 |
$order_0_1->populate_with_prices_for_ordering(); |
|
|
456 |
|
494 |
|
457 |
# If a unitprice is provided at ordering, we calculate the tax from that |
495 |
# format_for_editing |
458 |
compare( |
496 |
for my $currency_format ( qw( US FR ) ) { |
459 |
{ |
497 |
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); |
460 |
got => $order_0_1->tax_value_on_ordering, |
498 |
is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' ); |
461 |
expected => 7.75, |
499 |
is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' ); |
462 |
conf => '0 1', |
500 |
} |
463 |
field => 'tax_value' |
501 |
}; |
464 |
} |
|
|
465 |
); |
466 |
$order_0_1->populate_with_prices_for_receiving(); |
467 |
|
502 |
|
468 |
compare( |
503 |
$schema->storage->txn_rollback; |
469 |
{ |
|
|
470 |
got => $order_0_1->unitprice_tax_included, |
471 |
expected => 77.49, |
472 |
conf => '0 1', |
473 |
field => 'unitprice_tax_included' |
474 |
} |
475 |
); |
476 |
compare( |
477 |
{ |
478 |
got => $order_0_1->unitprice_tax_excluded, |
479 |
expected => 73.80, |
480 |
conf => '0 1', |
481 |
field => 'unitprice_tax_excluded' |
482 |
} |
483 |
); |
484 |
compare( |
485 |
{ |
486 |
got => $order_0_1->tax_value_on_receiving, |
487 |
expected => 7.38, |
488 |
conf => '0 1', |
489 |
field => 'tax_value' |
490 |
} |
491 |
); |
492 |
}; |
493 |
} |
494 |
|
495 |
sub compare { |
496 |
my ($params) = @_; |
497 |
is( |
498 |
Koha::Number::Price->new( $params->{got} )->format, |
499 |
Koha::Number::Price->new( $params->{expected} )->format, |
500 |
"configuration $params->{conf}: $params->{field} should be correctly calculated" |
501 |
); |
502 |
} |
503 |
|
504 |
# format_for_editing |
505 |
for my $currency_format ( qw( US FR ) ) { |
506 |
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format ); |
507 |
is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' ); |
508 |
is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' ); |
509 |
} |
510 |
- |
|
|