Bugzilla – Attachment 58106 Details for
Bug 17736
Move GetReservesFromBiblionumber to Koha::Biblio->holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17736: Add the Koha::Biblio->holds_placed_before_today method
Bug-17736-Add-the-KohaBiblio-holdsplacedbeforetoda.patch (text/plain), 3.06 KB, created by
Jonathan Druart
on 2016-12-12 10:18:56 UTC
(
hide
)
Description:
Bug 17736: Add the Koha::Biblio->holds_placed_before_today method
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-12-12 10:18:56 UTC
Size:
3.06 KB
patch
obsolete
>From 24250007f478273d5ee903e319cc632853d40bb5 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 7 Dec 2016 16:38:38 +0100 >Subject: [PATCH] Bug 17736: Add the Koha::Biblio->holds_placed_before_today > method > >--- > Koha/Biblio.pm | 23 ++++++++++++++++++++--- > t/db_dependent/Koha/Biblios.t | 15 +++++++++++++-- > 2 files changed, 33 insertions(+), 5 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index d5ca370..5b3ce08 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -24,6 +24,7 @@ use Carp; > use C4::Biblio qw( GetRecordValue GetMarcBiblio GetFrameworkCode ); > > use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); > > use base qw(Koha::Object); > >@@ -258,10 +259,26 @@ return the current holds placed on this record > =cut > > sub holds { >- my ( $self ) = @_; >+ my ( $self, $params, $attributes ) = @_; >+ $attributes->{order_by} = 'priority' unless exists $attributes->{order_by}; >+ my $hold_rs = $self->_result->reserves->search( $params, $attributes ); >+ return Koha::Holds->_new_from_dbic($hold_rs); >+} >+ >+=head3 holds_placed_before_today >+ >+my $holds = $biblio->holds_placed_before_today > >- my $holds_rs = $self->_result->reserves; >- return Koha::Holds->_new_from_dbic( $holds_rs ); >+Return the holds placed on this bibliographic record. >+It does not include future holds. >+ >+=cut >+ >+sub holds_placed_before_today { >+ my ($self) = @_; >+ my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ return $self->holds( >+ { reservedate => { '<=' => $dtf->format_date(dt_from_string) } } ); > } > > =head3 biblioitem >diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t >index 2498b86..dce43ad 100644 >--- a/t/db_dependent/Koha/Biblios.t >+++ b/t/db_dependent/Koha/Biblios.t >@@ -23,6 +23,7 @@ use Test::More tests => 1; > > use C4::Reserves; > >+use Koha::DateUtils qw( dt_from_string ); > use Koha::Biblios; > use Koha::Patrons; > use t::lib::TestBuilder; >@@ -43,13 +44,23 @@ my $biblioitem = $schema->resultset('Biblioitem')->new( > } > )->insert(); > >-subtest 'holds' => sub { >- plan tests => 3; >+subtest 'holds + holds_placed_before_today' => sub { >+ plan tests => 5; > C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber ); > my $holds = $biblio->holds; > is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' ); > is( $holds->count, 1, '->holds should only return 1 hold' ); > is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' ); >+ $holds->delete; >+ >+ # Add a hold in the future >+ C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber, undef, undef, dt_from_string->add( days => 2 ) ); >+ $holds = $biblio->holds; >+ is( $holds->count, 1, '->holds should return future holds' ); >+ $holds = $biblio->holds_placed_before_today; >+ is( $holds->count, 0, '->holds_placed_before_today should not return future holds' ); >+ $holds->delete; >+ > }; > > $schema->storage->txn_rollback; >-- >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 17736
:
58015
|
58016
|
58017
|
58056
|
58057
|
58106
|
58107
|
58108
|
58628
|
58629
|
58630
|
58631
|
58632
|
58633
|
58634
|
58635
|
58636
|
58637
|
58638
|
58639
|
58640
|
58641
|
58642
|
58643
|
58644
|
58645
|
59846
|
59847
|
59848
|
59849
|
59850
|
59851
|
59852
|
59853
|
59854
|
59855
|
59859
|
59860
|
61406
|
61407
|
61408
|
61409
|
61410
|
61411
|
61412
|
61413
|
61414
|
61415
|
61416