Bugzilla – Attachment 57929 Details for
Bug 17586
Add the Koha::Account->balance method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17586: Add the Koha::Account::Lines->get_balance method
Bug-17586-Add-the-KohaAccountLines-getbalance-meth.patch (text/plain), 2.73 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-12-02 15:43:03 UTC
(
hide
)
Description:
Bug 17586: Add the Koha::Account::Lines->get_balance method
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-12-02 15:43:03 UTC
Size:
2.73 KB
patch
obsolete
>From 13ffa8929a14735743b834ff71dd585abe3caf7b Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 8 Nov 2016 13:50:10 +0000 >Subject: [PATCH] Bug 17586: Add the Koha::Account::Lines->get_balance method > >Test plan: > prove t/db_dependent/Accounts.t >should return green > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Account/Lines.pm | 20 ++++++++++++++++++++ > t/db_dependent/Accounts.t | 37 ++++++++++++++++++++++++++++++++++++- > 2 files changed, 56 insertions(+), 1 deletion(-) > >diff --git a/Koha/Account/Lines.pm b/Koha/Account/Lines.pm >index 0e0677c..aa54e0c 100644 >--- a/Koha/Account/Lines.pm >+++ b/Koha/Account/Lines.pm >@@ -36,6 +36,26 @@ 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 afbe8e9..864f4f4 100644 >--- a/t/db_dependent/Accounts.t >+++ b/t/db_dependent/Accounts.t >@@ -18,7 +18,7 @@ > > use Modern::Perl; > >-use Test::More tests => 19; >+use Test::More tests => 20; > use Test::MockModule; > use Test::Warn; > >@@ -356,4 +356,39 @@ subtest "makepartialpayment() tests" => sub { > } > }; > >+subtest 'get_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 $accountline_1 = $builder->build( >+ { >+ source => 'Accountline', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ amount => 42, >+ amountoutstanding => 42 >+ } >+ } >+ ); >+ my $accountline_2 = $builder->build( >+ { >+ source => 'Accountline', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ amount => -13, >+ amountoutstanding => -13 >+ } >+ } >+ ); >+ >+ my $balance = $patron->get_account_lines->get_balance; >+ is( int($balance), 29, 'get_balance should return the correct value'); >+ >+ $patron->delete; >+}; >+ > 1; >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17586
:
57337
|
57338
|
57906
|
57929
|
57990
|
57991