Lines 60-69
subtest 'outstanding_debits() tests' => sub {
Link Here
|
60 |
my $account = $patron->account; |
60 |
my $account = $patron->account; |
61 |
|
61 |
|
62 |
my @generated_lines; |
62 |
my @generated_lines; |
63 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
63 |
push @generated_lines, $account->add_debit({ amount => 1, interface => 'commandline', type => 'fine' }); |
64 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
64 |
push @generated_lines, $account->add_debit({ amount => 2, interface => 'commandline', type => 'fine' }); |
65 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
65 |
push @generated_lines, $account->add_debit({ amount => 3, interface => 'commandline', type => 'fine' }); |
66 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
66 |
push @generated_lines, $account->add_debit({ amount => 4, interface => 'commandline', type => 'fine' }); |
67 |
|
67 |
|
68 |
my $lines = $account->outstanding_debits(); |
68 |
my $lines = $account->outstanding_debits(); |
69 |
my @lines_arr = $account->outstanding_debits(); |
69 |
my @lines_arr = $account->outstanding_debits(); |
Lines 89-99
subtest 'outstanding_debits() tests' => sub {
Link Here
|
89 |
my $the_line = Koha::Account::Lines->find( $just_one->id ); |
89 |
my $the_line = Koha::Account::Lines->find( $just_one->id ); |
90 |
is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line"); |
90 |
is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line"); |
91 |
|
91 |
|
92 |
my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); |
92 |
my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); |
93 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2, amountoutstanding => -2, interface => 'commandline' })->store; |
93 |
my $account_3 = $patron_3->account; |
94 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20, amountoutstanding => -20, interface => 'commandline' })->store; |
94 |
$account_3->add_credit( { amount => 2, interface => 'commandline' } ); |
95 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200, interface => 'commandline' })->store; |
95 |
$account_3->add_credit( { amount => 20, interface => 'commandline' } ); |
96 |
$lines = $patron_3->account->outstanding_debits(); |
96 |
$account_3->add_credit( { amount => 200, interface => 'commandline' } ); |
|
|
97 |
$lines = $account_3->outstanding_debits(); |
97 |
is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" ); |
98 |
is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" ); |
98 |
is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" ); |
99 |
is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" ); |
99 |
|
100 |
|
Lines 157-163
subtest 'outstanding_credits() tests' => sub {
Link Here
|
157 |
|
158 |
|
158 |
subtest 'add_credit() tests' => sub { |
159 |
subtest 'add_credit() tests' => sub { |
159 |
|
160 |
|
160 |
plan tests => 15; |
161 |
plan tests => 16; |
161 |
|
162 |
|
162 |
$schema->storage->txn_begin; |
163 |
$schema->storage->txn_begin; |
163 |
|
164 |
|
Lines 173-178
subtest 'add_credit() tests' => sub {
Link Here
|
173 |
# Disable logs |
174 |
# Disable logs |
174 |
t::lib::Mocks::mock_preference( 'FinesLog', 0 ); |
175 |
t::lib::Mocks::mock_preference( 'FinesLog', 0 ); |
175 |
|
176 |
|
|
|
177 |
throws_ok { |
178 |
$account->add_credit( |
179 |
{ amount => 25, |
180 |
description => 'Payment of 25', |
181 |
library_id => $patron->branchcode, |
182 |
note => 'not really important', |
183 |
type => 'payment', |
184 |
user_id => $patron->id |
185 |
} |
186 |
); |
187 |
} |
188 |
'Koha::Exceptions::MissingParameter', 'Exception thrown if interface parameter missing'; |
189 |
|
176 |
my $line_1 = $account->add_credit( |
190 |
my $line_1 = $account->add_credit( |
177 |
{ amount => 25, |
191 |
{ amount => 25, |
178 |
description => 'Payment of 25', |
192 |
description => 'Payment of 25', |
Lines 236-242
subtest 'add_credit() tests' => sub {
Link Here
|
236 |
|
250 |
|
237 |
subtest 'add_debit() tests' => sub { |
251 |
subtest 'add_debit() tests' => sub { |
238 |
|
252 |
|
239 |
plan tests => 13; |
253 |
plan tests => 14; |
240 |
|
254 |
|
241 |
$schema->storage->txn_begin; |
255 |
$schema->storage->txn_begin; |
242 |
|
256 |
|
Lines 276-281
subtest 'add_debit() tests' => sub {
Link Here
|
276 |
} |
290 |
} |
277 |
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; |
291 |
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; |
278 |
|
292 |
|
|
|
293 |
throws_ok { |
294 |
$account->add_debit( |
295 |
{ |
296 |
amount => 25, |
297 |
description => 'Rental charge of 25', |
298 |
library_id => $patron->branchcode, |
299 |
note => 'not really important', |
300 |
type => 'rent', |
301 |
user_id => $patron->id |
302 |
} |
303 |
); } 'Koha::Exceptions::MissingParameter', 'Exception thrown if interface parameter missing'; |
304 |
|
279 |
# Disable logs |
305 |
# Disable logs |
280 |
t::lib::Mocks::mock_preference( 'FinesLog', 0 ); |
306 |
t::lib::Mocks::mock_preference( 'FinesLog', 0 ); |
281 |
|
307 |
|
Lines 354-379
subtest 'lines() tests' => sub {
Link Here
|
354 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
380 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
355 |
my $account = $patron->account; |
381 |
my $account = $patron->account; |
356 |
|
382 |
|
357 |
my @generated_lines; |
|
|
358 |
|
359 |
# Add Credits |
383 |
# Add Credits |
360 |
push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' }); |
384 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
361 |
push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' }); |
385 |
$account->add_credit({ amount => 2, interface => 'commandline' }); |
362 |
push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' }); |
386 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
363 |
push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' }); |
387 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
364 |
|
388 |
|
365 |
# Add Debits |
389 |
# Add Debits |
366 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1, interface => 'commandline' })->store; |
390 |
$account->add_debit({ amount => 1, interface => 'commandline', type => 'fine' }); |
367 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2, interface => 'commandline' })->store; |
391 |
$account->add_debit({ amount => 2, interface => 'commandline', type => 'fine' }); |
368 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3, interface => 'commandline' })->store; |
392 |
$account->add_debit({ amount => 3, interface => 'commandline', type => 'fine' }); |
369 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4, interface => 'commandline' })->store; |
393 |
$account->add_debit({ amount => 4, interface => 'commandline', type => 'fine' }); |
370 |
|
394 |
|
371 |
# Paid Off |
395 |
# Paid Off |
372 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store; |
396 |
$account->add_credit( { amount => 1, interface => 'commandline' } ) |
373 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store; |
397 |
->apply( { debits => scalar $account->outstanding_debits } ); |
374 |
|
398 |
|
375 |
my $lines = $account->lines; |
399 |
my $lines = $account->lines; |
376 |
is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched"); |
400 |
is( $lines->_resultset->count, 9, "All accountlines (debits, credits and paid off) were fetched"); |
377 |
|
401 |
|
378 |
$schema->storage->txn_rollback; |
402 |
$schema->storage->txn_rollback; |
379 |
}; |
403 |
}; |
Lines 398-408
subtest 'reconcile_balance' => sub {
Link Here
|
398 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
422 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
399 |
$account->add_credit({ amount => 5, interface => 'commandline' }); |
423 |
$account->add_credit({ amount => 5, interface => 'commandline' }); |
400 |
|
424 |
|
401 |
# Add Debits TODO: replace for calls to add_debit when time comes |
425 |
# Add Debits |
402 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
426 |
$account->add_debit({ amount => 1, interface => 'commandline', type => 'fine' }); |
403 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
427 |
$account->add_debit({ amount => 2, interface => 'commandline', type => 'fine' }); |
404 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
428 |
$account->add_debit({ amount => 3, interface => 'commandline', type => 'fine' }); |
405 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
429 |
$account->add_debit({ amount => 4, interface => 'commandline', type => 'fine' }); |
406 |
|
430 |
|
407 |
# Paid Off |
431 |
# Paid Off |
408 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
432 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
Lines 436-446
subtest 'reconcile_balance' => sub {
Link Here
|
436 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
460 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
437 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
461 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
438 |
|
462 |
|
439 |
# Add Debits TODO: replace for calls to add_debit when time comes |
463 |
# Add Debits |
440 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
464 |
$account->add_debit({ amount => 1, interface => 'commandline', type => 'fine' }); |
441 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
465 |
$account->add_debit({ amount => 2, interface => 'commandline', type => 'fine' }); |
442 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
466 |
$account->add_debit({ amount => 3, interface => 'commandline', type => 'fine' }); |
443 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
467 |
$account->add_debit({ amount => 4, interface => 'commandline', type => 'fine' }); |
444 |
|
468 |
|
445 |
# Paid Off |
469 |
# Paid Off |
446 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
470 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
Lines 474-485
subtest 'reconcile_balance' => sub {
Link Here
|
474 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
498 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
475 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
499 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
476 |
|
500 |
|
477 |
# Add Debits TODO: replace for calls to add_debit when time comes |
501 |
# Add Debits |
478 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
502 |
$account->add_debit({ amount => 1, interface => 'commandline', type => 'fine' }); |
479 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
503 |
$account->add_debit({ amount => 2, interface => 'commandline', type => 'fine' }); |
480 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
504 |
$account->add_debit({ amount => 3, interface => 'commandline', type => 'fine' }); |
481 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
505 |
$account->add_debit({ amount => 4, interface => 'commandline', type => 'fine' }); |
482 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5, interface => 'commandline' })->store; |
506 |
$account->add_debit({ amount => 5, interface => 'commandline', type => 'fine' }); |
483 |
|
507 |
|
484 |
# Paid Off |
508 |
# Paid Off |
485 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
509 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
Lines 511-520
subtest 'reconcile_balance' => sub {
Link Here
|
511 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
535 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
512 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
536 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
513 |
|
537 |
|
514 |
# Add Debits TODO: replace for calls to add_debit when time comes |
538 |
# Add Debits |
515 |
my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
539 |
my $debit_1 = $account->add_debit({ amount => 1, interface => 'commandline', type => 'fine' }); |
516 |
my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
540 |
my $debit_2 = $account->add_debit({ amount => 2, interface => 'commandline', type => 'fine' }); |
517 |
my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
541 |
my $debit_3 = $account->add_debit({ amount => 3, interface => 'commandline', type => 'fine' }); |
518 |
|
542 |
|
519 |
is( $account->balance(), 2, "Account balance is 2" ); |
543 |
is( $account->balance(), 2, "Account balance is 2" ); |
520 |
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' ); |
544 |
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' ); |
521 |
- |
|
|