Bugzilla – Attachment 57362 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]
[SIGNED-OFF] Bug 17580: Add the Koha::Patron->get_overdues method
SIGNED-OFF-Bug-17580-Add-the-KohaPatron-getoverdue.patch (text/plain), 4.54 KB, created by
Josef Moravec
on 2016-11-09 07:10:51 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17580: Add the Koha::Patron->get_overdues method
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-11-09 07:10:51 UTC
Size:
4.54 KB
patch
obsolete
>From 75b67f3718d3df84ba0f389a1c20b5f304a87e67 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] [SIGNED-OFF] 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 > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > 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 9a2fd18..27a7af8 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -449,6 +449,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 a5ad0bf..d15e351 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; > >@@ -513,6 +516,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