Bug 20990: (QA follow-up) make outstanding_credits return the account lines only

This patch was discussed with Jonathan on a QA conversation. It is
better to keep this simpler and more reusable. And is the right approach
in this case.

This patch makes Koha::Account::outstanding_credits return the account
lines, code that used the $total value, will just use

    $lines->total_outstanding;

Tests are adjusted accordingly.

To test:
- Run:
  $ kshell
 k$ prove t/db_dependent/Koha/Account.t
=> SUCCESS: Test pass.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2018-07-02 15:59:54 -03:00 committed by Nick Clemens
parent 3e0aa0f319
commit 9bfb3bc378
2 changed files with 8 additions and 10 deletions

View File

@ -424,7 +424,7 @@ sub outstanding_debits {
=head3 outstanding_credits
my ( $total, $lines ) = Koha::Account->new({ patron_id => $patron_id })->outstanding_credits;
my $lines = Koha::Account->new({ patron_id => $patron_id })->outstanding_credits;
=cut
@ -438,10 +438,7 @@ sub outstanding_credits {
}
);
# sum returns undef if list is empty
my $total = sum0( $lines->get_column('amountoutstanding') );
return ( $total, $lines );
return $lines;
}
=head3 non_issues_charges

View File

@ -90,7 +90,7 @@ subtest 'outstanding_credits() tests' => sub {
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $account = Koha::Account->new({ patron_id => $patron->id });
my $account = $patron->account;
my @generated_lines;
push @generated_lines, $account->add_credit({ amount => 1 });
@ -98,9 +98,9 @@ subtest 'outstanding_credits() tests' => sub {
push @generated_lines, $account->add_credit({ amount => 3 });
push @generated_lines, $account->add_credit({ amount => 4 });
my ( $total, $lines ) = $account->outstanding_credits();
my $lines = $account->outstanding_credits();
is( $total, -10, 'Outstandig credits total is correctly calculated' );
is( $lines->total_outstanding, -10, 'Outstandig credits total is correctly calculated' );
my $i = 0;
foreach my $line ( @{ $lines->as_list } ) {
@ -109,8 +109,9 @@ subtest 'outstanding_credits() tests' => sub {
$i++;
}
( $total, $lines ) = Koha::Account->new({ patron_id => 'InvalidBorrowernumber' })->outstanding_credits();
is( $total, 0, "Total if no outstanding credits is 0" );
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
$lines = $patron_2->account->outstanding_credits();
is( $lines->total_outstanding, 0, "Total if no outstanding credits is 0" );
is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
$schema->storage->txn_rollback;