From 35a8fe0bd11777c785d9d4ca73edb05fdc1f1ecd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 6 Dec 2016 09:12:57 +0100 Subject: [PATCH] Bug 17586: Move ->get_balance to Koha::Account->balance Signed-off-by: Kyle M Hall --- Koha/Account.pm | 24 ++++++++++++++++++++++++ Koha/Account/Lines.pm | 20 -------------------- t/db_dependent/Accounts.t | 10 +++++----- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 93b9f62654..7041cb2c75 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -223,6 +223,30 @@ sub pay { return $payment->id; } +=head3 balance + +my $balance = $self->balance + +Return the balance (sum of amountoutstanding columns) + +=cut + +sub balance { + my ($self) = @_; + my $fines = Koha::Account::Lines->search( + { + borrowernumber => $self->{patron_id}, + }, + { + select => [ { sum => 'amountoutstanding' } ], + as => ['total_amountoutstanding'], + } + ); + return $fines->count + ? $fines->next->get_column('total_amountoutstanding') + : 0; +} + 1; =head1 AUTHOR diff --git a/Koha/Account/Lines.pm b/Koha/Account/Lines.pm index aa54e0c6cf..0e0677ca85 100644 --- a/Koha/Account/Lines.pm +++ b/Koha/Account/Lines.pm @@ -36,26 +36,6 @@ Koha::Account::Lines - Koha Account Line Object set class =cut -=head3 get_balance - -my $balance = $self->get_balance - -Return the balance (sum of amountoutstanding columns) - -=cut - -sub get_balance { - my ($self) = @_; - my $fines = $self->search( - {}, - { - select => [ { sum => 'amountoutstanding' } ], - as => ['total_amountoutstanding'] - } - ); - return $fines->count ? $fines->next->get_column('total_amountoutstanding') : 0; -} - =head3 type =cut diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index f9d1d80b6d..a2a96b212b 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -365,13 +365,13 @@ subtest "makepartialpayment() tests" => sub { } }; -subtest 'get_balance' => sub { +subtest 'balance' => sub { plan tests => 2; my $patron = $builder->build({source => 'Borrower'}); $patron = Koha::Patrons->find( $patron->{borrowernumber} ); - my $account_lines = $patron->get_account_lines; - is( $account_lines->get_balance, 0, 'get_balance should return 0 if the patron does not have fines' ); + my $account = $patron->account; + is( $account->balance, 0, 'balance should return 0 if the patron does not have fines' ); my $accountline_1 = $builder->build( { @@ -394,8 +394,8 @@ subtest 'get_balance' => sub { } ); - my $balance = $patron->get_account_lines->get_balance; - is( int($balance), 29, 'get_balance should return the correct value'); + my $balance = $patron->account->balance; + is( int($balance), 29, 'balance should return the correct value'); $patron->delete; }; -- 2.39.5