Bug 17586: Move ->get_balance to Koha::Account->balance
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 6 Dec 2016 08:12:57 +0000 (09:12 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 16 Dec 2016 14:50:18 +0000 (14:50 +0000)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Koha/Account.pm
Koha/Account/Lines.pm
t/db_dependent/Accounts.t

index 93b9f62..7041cb2 100644 (file)
@@ -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
index aa54e0c..0e0677c 100644 (file)
@@ -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
index f9d1d80..a2a96b2 100644 (file)
@@ -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;
 };