Bugzilla – Attachment 57314 Details for
Bug 17580
Add the Koha::Patron->get_overdues method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17580: Add the Koha::Patron->get_overdues method
Bug-17580-Add-the-KohaPatron-getoverdues-method.patch (text/plain), 4.48 KB, created by
Jonathan Druart
on 2016-11-08 12:37:35 UTC
(
hide
)
Description:
Bug 17580: Add the Koha::Patron->get_overdues method
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-11-08 12:37:35 UTC
Size:
4.48 KB
patch
obsolete
>From 7551197e1e1b1c9a34910a27baabf77b50e0d284 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 8 Nov 2016 12:16:49 +0000 >Subject: [PATCH] Bug 17580: Add the Koha::Patron->get_overdues method > >This method will be used by several patches later. > >Test plan: > prove t/db_dependent/Koha/Patrons.t >should return green >--- > Koha/Patron.pm | 23 ++++++++++++++ > t/db_dependent/Koha/Patrons.t | 70 ++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 92 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 04a472e..ca78d96 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -465,6 +465,29 @@ sub add_enrolment_fee_if_needed { > return $enrolment_fee || 0; > } > >+=head3 get_overdues >+ >+my $overdue_items = $patron->get_overdues >+ >+Return the overdued items >+ >+=cut >+ >+sub get_overdues { >+ my ($self) = @_; >+ my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ my $issues = Koha::Issues->search( >+ { >+ 'me.borrowernumber' => $self->borrowernumber, >+ 'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) }, >+ }, >+ { >+ prefetch => { item => { biblio => 'biblioitems' } }, >+ } >+ ); >+ return $issues; >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 439f4f0..e4c7581 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,9 +19,12 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 13; > use Test::Warn; >+use DateTime; > >+use C4::Biblio; >+use C4::Circulation; > use C4::Members; > use C4::Circulation; > >@@ -531,6 +534,71 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { > Koha::Patrons->find( $userenv_patron->{borrowernumber})->delete; > }; > >+subtest 'get_overdues' => sub { >+ plan tests => 4; >+ >+ my $library = $builder->build( { source => 'Branch' } ); >+ my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' ); >+ my $item_1 = $builder->build( >+ { >+ source => 'Item', >+ value => { >+ homebranch => $library->{branchcode}, >+ holdingbranch => $library->{branchcode}, >+ biblionumber => $biblionumber_1 >+ } >+ } >+ ); >+ my $item_2 = $builder->build( >+ { >+ source => 'Item', >+ value => { >+ homebranch => $library->{branchcode}, >+ holdingbranch => $library->{branchcode}, >+ biblionumber => $biblionumber_1 >+ } >+ } >+ ); >+ my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' ); >+ my $item_3 = $builder->build( >+ { >+ source => 'Item', >+ value => { >+ homebranch => $library->{branchcode}, >+ holdingbranch => $library->{branchcode}, >+ biblionumber => $biblionumber_2 >+ } >+ } >+ ); >+ my $patron = $builder->build( >+ { >+ source => 'Borrower', >+ value => { branchcode => $library->{branchcode} } >+ } >+ ); >+ >+ # Not sure how this is useful, but AddIssue pass this variable to different other subroutines >+ $patron = GetMember( borrowernumber => $patron->{borrowernumber} ); >+ >+ my $module = new Test::MockModule('C4::Context'); >+ $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } ); >+ >+ AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) ); >+ AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) ); >+ AddIssue( $patron, $item_3->{barcode} ); >+ >+ $patron = Koha::Patrons->find( $patron->{borrowernumber} ); >+ my $overdues = $patron->get_overdues; >+ is( $overdues->count, 2, 'Patron should have 2 overdues'); >+ is( ref($overdues), 'Koha::Issues', 'Koha::Patron->get_overdues should return Koha::Issues' ); >+ is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' ); >+ is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' ); >+ >+ # Clean stuffs >+ Koha::Issues->search( { borrowernumber => $patron->borrowernumber } )->delete; >+ $patron->delete; >+}; >+ > $retrieved_patron_1->delete; > is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); > >-- >2.1.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 17580
:
57309
|
57311
|
57314
|
57362
|
57828
|
57927