Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 14; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
|
24 |
|
25 |
use C4::Circulation qw/AddIssue AddReturn/; |
25 |
use C4::Circulation qw/AddIssue AddReturn/; |
Lines 178-183
subtest 'total_outstanding() tests' => sub {
Link Here
|
178 |
$schema->storage->txn_rollback; |
178 |
$schema->storage->txn_rollback; |
179 |
}; |
179 |
}; |
180 |
|
180 |
|
|
|
181 |
subtest 'total() tests' => sub { |
182 |
|
183 |
plan tests => 5; |
184 |
|
185 |
$schema->storage->txn_begin; |
186 |
|
187 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
188 |
|
189 |
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
190 |
is( $lines->total, 0, 'total returns 0 if no lines (undef case)' ); |
191 |
|
192 |
my $debit_1 = Koha::Account::Line->new( |
193 |
{ borrowernumber => $patron->id, |
194 |
debit_type_code => "OVERDUE", |
195 |
status => "RETURNED", |
196 |
amount => 10, |
197 |
amountoutstanding => 10, |
198 |
interface => 'commandline', |
199 |
} |
200 |
)->store; |
201 |
|
202 |
my $debit_2 = Koha::Account::Line->new( |
203 |
{ borrowernumber => $patron->id, |
204 |
debit_type_code => "OVERDUE", |
205 |
status => "RETURNED", |
206 |
amount => 10, |
207 |
amountoutstanding => 10, |
208 |
interface => 'commandline', |
209 |
} |
210 |
)->store; |
211 |
|
212 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
213 |
is( $lines->total, 20, 'total sums correctly' ); |
214 |
|
215 |
my $credit_1 = Koha::Account::Line->new( |
216 |
{ borrowernumber => $patron->id, |
217 |
debit_type_code => "OVERDUE", |
218 |
status => "RETURNED", |
219 |
amount => -10, |
220 |
amountoutstanding => -10, |
221 |
interface => 'commandline', |
222 |
} |
223 |
)->store; |
224 |
|
225 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
226 |
is( $lines->total, 10, 'total sums correctly' ); |
227 |
|
228 |
my $credit_2 = Koha::Account::Line->new( |
229 |
{ borrowernumber => $patron->id, |
230 |
debit_type_code => "OVERDUE", |
231 |
status => "RETURNED", |
232 |
amount => -10, |
233 |
amountoutstanding => -10, |
234 |
interface => 'commandline', |
235 |
} |
236 |
)->store; |
237 |
|
238 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
239 |
is( $lines->total, 0, 'total sums correctly' ); |
240 |
|
241 |
my $credit_3 = Koha::Account::Line->new( |
242 |
{ borrowernumber => $patron->id, |
243 |
debit_type_code => "OVERDUE", |
244 |
status => "RETURNED", |
245 |
amount => -100, |
246 |
amountoutstanding => -100, |
247 |
interface => 'commandline', |
248 |
} |
249 |
)->store; |
250 |
|
251 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
252 |
is( $lines->total, -100, 'total sums correctly' ); |
253 |
|
254 |
$schema->storage->txn_rollback; |
255 |
}; |
256 |
|
257 |
subtest 'credits_total() tests' => sub { |
258 |
|
259 |
plan tests => 5; |
260 |
|
261 |
$schema->storage->txn_begin; |
262 |
|
263 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
264 |
|
265 |
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
266 |
is( $lines->credits_total, 0, 'credits_total returns 0 if no lines (undef case)' ); |
267 |
|
268 |
my $debit_1 = Koha::Account::Line->new( |
269 |
{ borrowernumber => $patron->id, |
270 |
debit_type_code => "OVERDUE", |
271 |
status => "RETURNED", |
272 |
amount => 10, |
273 |
amountoutstanding => 10, |
274 |
interface => 'commandline', |
275 |
} |
276 |
)->store; |
277 |
|
278 |
my $debit_2 = Koha::Account::Line->new( |
279 |
{ borrowernumber => $patron->id, |
280 |
debit_type_code => "OVERDUE", |
281 |
status => "RETURNED", |
282 |
amount => 10, |
283 |
amountoutstanding => 10, |
284 |
interface => 'commandline', |
285 |
} |
286 |
)->store; |
287 |
|
288 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
289 |
is( $lines->credits_total, 0, 'credits_total sums correctly' ); |
290 |
|
291 |
my $credit_1 = Koha::Account::Line->new( |
292 |
{ borrowernumber => $patron->id, |
293 |
debit_type_code => "OVERDUE", |
294 |
status => "RETURNED", |
295 |
amount => -10, |
296 |
amountoutstanding => -10, |
297 |
interface => 'commandline', |
298 |
} |
299 |
)->store; |
300 |
|
301 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
302 |
is( $lines->credits_total, -10, 'credits_total sums correctly' ); |
303 |
|
304 |
my $credit_2 = Koha::Account::Line->new( |
305 |
{ borrowernumber => $patron->id, |
306 |
debit_type_code => "OVERDUE", |
307 |
status => "RETURNED", |
308 |
amount => -10, |
309 |
amountoutstanding => -10, |
310 |
interface => 'commandline', |
311 |
} |
312 |
)->store; |
313 |
|
314 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
315 |
is( $lines->credits_total, -20, 'credits_total sums correctly' ); |
316 |
|
317 |
my $credit_3 = Koha::Account::Line->new( |
318 |
{ borrowernumber => $patron->id, |
319 |
debit_type_code => "OVERDUE", |
320 |
status => "RETURNED", |
321 |
amount => -100, |
322 |
amountoutstanding => -100, |
323 |
interface => 'commandline', |
324 |
} |
325 |
)->store; |
326 |
|
327 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
328 |
is( $lines->credits_total, -120, 'credits_total sums correctly' ); |
329 |
|
330 |
$schema->storage->txn_rollback; |
331 |
}; |
332 |
|
333 |
subtest 'debits_total() tests' => sub { |
334 |
|
335 |
plan tests => 5; |
336 |
|
337 |
$schema->storage->txn_begin; |
338 |
|
339 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
340 |
|
341 |
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
342 |
is( $lines->debits_total, 0, 'debits_total returns 0 if no lines (undef case)' ); |
343 |
|
344 |
my $debit_1 = Koha::Account::Line->new( |
345 |
{ borrowernumber => $patron->id, |
346 |
debit_type_code => "OVERDUE", |
347 |
status => "RETURNED", |
348 |
amount => 10, |
349 |
amountoutstanding => 0, |
350 |
interface => 'commandline', |
351 |
} |
352 |
)->store; |
353 |
|
354 |
my $debit_2 = Koha::Account::Line->new( |
355 |
{ borrowernumber => $patron->id, |
356 |
debit_type_code => "OVERDUE", |
357 |
status => "RETURNED", |
358 |
amount => 10, |
359 |
amountoutstanding => 0, |
360 |
interface => 'commandline', |
361 |
} |
362 |
)->store; |
363 |
|
364 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
365 |
is( $lines->debits_total, 20, 'debits_total sums correctly' ); |
366 |
|
367 |
my $credit_1 = Koha::Account::Line->new( |
368 |
{ borrowernumber => $patron->id, |
369 |
debit_type_code => "OVERDUE", |
370 |
status => "RETURNED", |
371 |
amount => -10, |
372 |
amountoutstanding => 0, |
373 |
interface => 'commandline', |
374 |
} |
375 |
)->store; |
376 |
|
377 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
378 |
is( $lines->debits_total, 20, 'debits_total sums correctly' ); |
379 |
|
380 |
my $credit_2 = Koha::Account::Line->new( |
381 |
{ borrowernumber => $patron->id, |
382 |
debit_type_code => "OVERDUE", |
383 |
status => "RETURNED", |
384 |
amount => -10, |
385 |
amountoutstanding => 0, |
386 |
interface => 'commandline', |
387 |
} |
388 |
)->store; |
389 |
|
390 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
391 |
is( $lines->debits_total, 20, 'debits_total sums correctly' ); |
392 |
|
393 |
my $credit_3 = Koha::Account::Line->new( |
394 |
{ borrowernumber => $patron->id, |
395 |
debit_type_code => "OVERDUE", |
396 |
status => "RETURNED", |
397 |
amount => -100, |
398 |
amountoutstanding => 0, |
399 |
interface => 'commandline', |
400 |
} |
401 |
)->store; |
402 |
|
403 |
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id }); |
404 |
is( $lines->debits_total, 20, 'debits_total sums correctly' ); |
405 |
|
406 |
$schema->storage->txn_rollback; |
407 |
}; |
408 |
|
181 |
subtest 'is_credit() and is_debit() tests' => sub { |
409 |
subtest 'is_credit() and is_debit() tests' => sub { |
182 |
|
410 |
|
183 |
plan tests => 4; |
411 |
plan tests => 4; |
184 |
- |
|
|