Bugzilla – Attachment 76432 Details for
Bug 20946
Cannot pay fines for patrons with credits
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20946: Add Koha::Account::outstanding_debits
Bug-20946-Add-KohaAccountoutstandingdebits.patch (text/plain), 4.29 KB, created by
Kyle M Hall (khall)
on 2018-06-26 13:09:22 UTC
(
hide
)
Description:
Bug 20946: Add Koha::Account::outstanding_debits
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2018-06-26 13:09:22 UTC
Size:
4.29 KB
patch
obsolete
>From e6e101f2b77b34d7fb93877782be79b5d4910cf8 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Sat, 23 Jun 2018 05:41:00 -0300 >Subject: [PATCH] Bug 20946: Add Koha::Account::outstanding_debits > >This patch adds a handy method that returns the total for outstanding >debits (i.e. those that haven't been canceled with credits), and the >corresponding Koha::Account::Line objects. > >Unit tests are added. > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/db_dependent/Koha/Account.t >=> SUCCESS: tests pass! >- Sign off :-D > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Account.pm | 32 +++++++++++++++++++++++ > t/db_dependent/Koha/Account.t | 59 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 91 insertions(+) > create mode 100755 t/db_dependent/Koha/Account.t > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index 493f4ac698..02832d36c7 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -288,6 +288,38 @@ sub balance { > : 0; > } > >+=head3 outstanding_debits >+ >+my ( $total, $lines ) = Koha::Account->new({ patron_id => $patron_id })->outstanding_debits; >+ >+=cut >+ >+sub outstanding_debits { >+ my ($self) = @_; >+ >+ my $outstanding_debits = Koha::Account::Lines->search( >+ { borrowernumber => $self->{patron_id}, >+ amountoutstanding => { '>' => 0 } >+ }, >+ { select => [ { sum => 'amountoutstanding' } ], >+ as => ['outstanding_debits_total'], >+ } >+ ); >+ my $total >+ = ( $outstanding_debits->count ) >+ ? $outstanding_debits->next->get_column('outstanding_debits_total') + 0 >+ : 0; >+ >+ my $lines = Koha::Account::Lines->search( >+ { >+ borrowernumber => $self->{patron_id}, >+ amountoutstanding => { '>' => 0 } >+ } >+ ); >+ >+ return ( $total, $lines ); >+} >+ > =head3 non_issues_charges > > my $non_issues_charges = $self->non_issues_charges >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >new file mode 100755 >index 0000000000..bf0e0b677d >--- /dev/null >+++ b/t/db_dependent/Koha/Account.t >@@ -0,0 +1,59 @@ >+#!/usr/bin/perl >+ >+# Copyright 2018 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses> >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+ >+use Koha::Account; >+use Koha::Account::Lines; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'outstanding_debits() tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my @generated_lines; >+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store; >+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store; >+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store; >+ push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store; >+ >+ my $account = Koha::Account->new({ patron_id => $patron->id }); >+ my ( $total, $lines ) = $account->outstanding_debits(); >+ >+ is( $total, 10, 'Outstandig debits total is correctly calculated' ); >+ >+ my $i = 0; >+ foreach my $line ( @{ $lines->as_list } ) { >+ my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id ); >+ is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" ); >+ $i++; >+ } >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.15.2 (Apple Git-101.1)
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 20946
:
76116
|
76317
|
76318
|
76394
|
76395
| 76432 |
76433
|
76434
|
76435
|
76437
|
76519
|
76521
|
76522
|
76632