From 6ee9d8a888fa32a737116c15e9e5e5cae2f6653d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 2 Jul 2018 15:59:54 -0300 Subject: [PATCH] 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 Signed-off-by: Nick Clemens (cherry picked from commit 9bfb3bc3782dd6b516d0144074b57e55cbefae2e) Signed-off-by: Martin Renvoize --- Koha/Account.pm | 7 ++----- t/db_dependent/Koha/Account.t | 11 ++++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 82535159b6..036b34e429 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -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 diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 93b706d0e5..f6079a6cf0 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -88,7 +88,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 }); @@ -96,9 +96,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 } ) { @@ -107,8 +107,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; -- 2.39.5