Bugzilla – Attachment 55190 Details for
Bug 16851
Move HasOverdues to Koha::Patron->has_overdues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16851: Move HasOverdues to Koha::Patron->has_overdues
Bug-16851-Move-HasOverdues-to-KohaPatron-hasoverdu.patch (text/plain), 6.50 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-09-05 17:25:33 UTC
(
hide
)
Description:
Bug 16851: Move HasOverdues to Koha::Patron->has_overdues
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-09-05 17:25:33 UTC
Size:
6.50 KB
patch
obsolete
>From 297814ca5533e5f600969fcc34bb7dcf5bbc9536 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 4 Jul 2016 17:56:54 +0100 >Subject: [PATCH] Bug 16851: Move HasOverdues to Koha::Patron->has_overdues > >This patch just move C4::Members::HasOverdues to >Koha::Patron->has_overdues and updated callers > >Test plan: >No change in behavior is expected. >1/ If a patron is debarred and does not have overdues and >AutoRemoveOverduesRestrictions is on, the debarment will be removed on >checkin >2/ Add overdues and make sure the patron cannot renew > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Circulation.pm | 9 +++++---- > C4/Members.pm | 16 ---------------- > Koha/Patron.pm | 14 ++++++++++++++ > Koha/Template/Plugin/Borrowers.pm | 2 +- > t/db_dependent/Koha/Patrons.t | 36 +++++++++++++++++++++++++++++++++++- > 5 files changed, 55 insertions(+), 22 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 0964050..a71aa5f 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2089,7 +2089,7 @@ sub AddReturn { > if ( $borrowernumber > && $borrower->{'debarred'} > && C4::Context->preference('AutoRemoveOverduesRestrictions') >- && !C4::Members::HasOverdues( $borrowernumber ) >+ && !Koha::Patrons->find( $borrowernumber )->has_overdues > && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } > ) { > DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); >@@ -2822,8 +2822,9 @@ sub CanBookBeRenewed { > > my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); > my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); >- my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred; >- my $hasoverdues = C4::Members::HasOverdues($borrowernumber); >+ my $patron = Koha::Patrons->find($borrowernumber); >+ my $restricted = $patron->is_debarred; >+ my $hasoverdues = $patron->has_overdues; > > if ( $restricted and $restrictionblockrenewing ) { > return ( 0, 'restriction'); >@@ -2996,7 +2997,7 @@ sub AddRenewal { > $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); > if ( $borrowernumber > && $borrower->{'debarred'} >- && !C4::Members::HasOverdues( $borrowernumber ) >+ && !Koha::Patrons->find( $borrowernumber )->has_overdues > && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } > ) { > DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); >diff --git a/C4/Members.pm b/C4/Members.pm >index 061172f..67c556b 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -93,7 +93,6 @@ BEGIN { > &IssueSlip > GetBorrowersWithEmail > >- HasOverdues > GetOverduesForPatron > ); > >@@ -2039,21 +2038,6 @@ sub AddEnrolmentFeeIfNeeded { > } > } > >-=head2 HasOverdues >- >-=cut >- >-sub HasOverdues { >- my ( $borrowernumber ) = @_; >- >- my $sql = "SELECT COUNT(*) FROM issues WHERE date_due < NOW() AND borrowernumber = ?"; >- my $sth = C4::Context->dbh->prepare( $sql ); >- $sth->execute( $borrowernumber ); >- my ( $count ) = $sth->fetchrow_array(); >- >- return $count; >-} >- > =head2 DeleteExpiredOpacRegistrations > > Delete accounts that haven't been upgraded from the 'temporary' category >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 42b066b..886f4d3 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -208,6 +208,20 @@ sub update_password { > return 1; > } > >+=head2 has_overdues >+ >+my $has_overdues = $patron->has_overdues; >+ >+Returns the number of patron's overdues >+ >+=cut >+ >+sub has_overdues { >+ my ($self) = @_; >+ my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count; >+} >+ > =head3 type > > =cut >diff --git a/Koha/Template/Plugin/Borrowers.pm b/Koha/Template/Plugin/Borrowers.pm >index dd99b9b..cb50312 100644 >--- a/Koha/Template/Plugin/Borrowers.pm >+++ b/Koha/Template/Plugin/Borrowers.pm >@@ -54,7 +54,7 @@ sub HasOverdues { > > return unless $borrowernumber; > >- return C4::Members::HasOverdues($borrowernumber); >+ return Koha::Patrons->find( $borrowernumber )->has_overdues; > } > > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 980bf84..f5b2e56 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,9 +19,10 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 7; > use Test::Warn; > >+use C4::Circulation; > use Koha::Patron; > use Koha::Patrons; > use Koha::Database; >@@ -55,6 +56,9 @@ my $new_patron_2 = Koha::Patron->new( > } > )->store; > >+C4::Context->_new_userenv('xxx'); >+C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', ''); >+ > is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' ); > > my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber ); >@@ -102,6 +106,36 @@ subtest 'siblings' => sub { > $retrieved_guarantee_1->delete; > }; > >+subtest 'has_overdues' => sub { >+ plan tests => 3; >+ >+ my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } ); >+ my $item_1 = $builder->build( >+ { source => 'Item', >+ value => { >+ homebranch => $library->{branchcode}, >+ holdingbranch => $library->{branchcode}, >+ notforloan => 0, >+ itemlost => 0, >+ withdrawn => 0, >+ biblionumber => $biblioitem_1->{biblionumber} >+ } >+ } >+ ); >+ my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); >+ is( $retrieved_patron->has_overdues, 0, ); >+ >+ my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 ); >+ my $issue = AddIssue( $new_patron_1->unblessed, $item_1->{barcode} ); >+ is( $retrieved_patron->has_overdues, 0, ); >+ AddReturn( $item_1->{barcode} ); >+ my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); >+ $issue = AddIssue( $new_patron_1->unblessed, $item_1->{barcode}, $yesterday ); >+ $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); >+ is( $retrieved_patron->has_overdues, 1, ); >+ AddReturn( $item_1->{barcode} ); >+}; >+ > subtest 'update_password' => sub { > plan tests => 7; > >-- >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 16851
:
53094
|
53325
|
53511
|
53996
| 55190 |
55425
|
55426