Bugzilla – Attachment 47963 Details for
Bug 15516
Allow to place a hold on first available item from a group of titles
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15516 - Holding first available item from x biblios only count 1 reserve
Bug-15516---Holding-first-available-item-from-x-bi.patch (text/plain), 6.04 KB, created by
Alex Arnaud
on 2016-02-12 11:21:11 UTC
(
hide
)
Description:
Bug 15516 - Holding first available item from x biblios only count 1 reserve
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2016-02-12 11:21:11 UTC
Size:
6.04 KB
patch
obsolete
>From 4f5fff3c098170ff5db70110583eb8beaee12625 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Fri, 12 Feb 2016 12:18:35 +0100 >Subject: [PATCH] Bug 15516 - Holding first available item from x biblios only > count 1 reserve > >--- > C4/Reserves.pm | 19 +++++- > opac/opac-reserve.pl | 6 +- > t/db_dependent/Reserves/ReserveCount.t | 116 ++++++++++++++++++++++++++++++++ > 3 files changed, 137 insertions(+), 4 deletions(-) > create mode 100644 t/db_dependent/Reserves/ReserveCount.t > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 5784997..db11ca4 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -295,6 +295,8 @@ are excluded from the list. > =cut > > sub GetReservesFromBiblionumber { >+ >+ > my ( $params ) = @_; > my $biblionumber = $params->{biblionumber} or return []; > my $itemnumber = $params->{itemnumber}; >@@ -611,15 +613,30 @@ sub GetReserveCount { > > my $dbh = C4::Context->dbh; > >+ my $count = 0; > my $query = " > SELECT COUNT(*) AS counter > FROM reserves > WHERE borrowernumber = ? >+ AND reserve_group_id is NULL > "; > my $sth = $dbh->prepare($query); > $sth->execute($borrowernumber); > my $row = $sth->fetchrow_hashref; >- return $row->{counter}; >+ $count += $row->{counter}; >+ >+ $query = " >+ SELECT COUNT(DISTINCT reserve_group_id) AS counter >+ FROM reserves >+ WHERE borrowernumber = ? >+ AND reserve_group_id is not NULL >+ "; >+ $sth = $dbh->prepare($query); >+ $sth->execute($borrowernumber); >+ $row = $sth->fetchrow_hashref; >+ $count += $row->{counter}; >+ >+ return $count; > } > > =head2 GetOtherReserves >diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl >index 277b2fe..cb7693c 100755 >--- a/opac/opac-reserve.pl >+++ b/opac/opac-reserve.pl >@@ -191,7 +191,7 @@ foreach my $biblioNumber (@biblionumbers) { > if ( $query->param('place_reserve') ) { > my $reserve_cnt = 0; > if ($maxreserves) { >- $reserve_cnt = GetReservesFromBorrowernumber( $borrowernumber ); >+ $reserve_cnt = GetReserveCount( $borrowernumber ); > } > > # List is composed of alternating biblio/item/branch >@@ -342,12 +342,12 @@ if ( IsDebarred($borrowernumber) ) { > } > > my @reserves = GetReservesFromBorrowernumber( $borrowernumber ); >-my $reserves_count = scalar(@reserves); >+my $reserves_count = GetReserveCount($borrowernumber); > $template->param( RESERVES => \@reserves ); > if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) { > $template->param( message => 1 ); > $noreserves = 1; >- $template->param( too_many_reserves => scalar(@reserves)); >+ $template->param( too_many_reserves => $reserves_count); > } > > unless ( $noreserves ) { >diff --git a/t/db_dependent/Reserves/ReserveCount.t b/t/db_dependent/Reserves/ReserveCount.t >new file mode 100644 >index 0000000..f5724a0 >--- /dev/null >+++ b/t/db_dependent/Reserves/ReserveCount.t >@@ -0,0 +1,116 @@ >+#!/usr/bin/perl >+ >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Test::More tests => 3; >+use t::lib::TestBuilder; >+ >+use C4::Context; >+use C4::Biblio; >+use C4::Items; >+use C4::Reserves; >+ >+use Koha::Database; >+ >+ >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; >+my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; >+my $borrower = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $branchcode, >+ categorycode => $categorycode >+ } >+}); >+my $borrowernumber = $borrower->{borrowernumber}; >+ >+my $biblio = $builder->build( { source => 'Biblio', } ); >+my $biblionumber = $biblio->{biblionumber}; >+ >+# Use AddReserve instead of TestBuilder because i don't manage >+# to make TestBuilder set reserve_group_id to null. Idea ? >+my $reserve_id = AddReserve($branchcode, $borrowernumber, >+$biblionumber, $biblionumber, 1, undef, undef, undef >+$biblio->{title}, undef, undef, undef); >+ >+is(GetReserveCount($borrowernumber), 1, 'Test borrower has 1 reserve.'); >+ >+my $reserves_group = $builder->build({ >+ source => 'ReserveGroup', >+ value => { >+ reserve_group_id => 1 >+ } >+}); >+ >+my $reserve2 = $builder->build({ >+ source => 'Reserve', >+ value => { >+ borrowernumber => $borrowernumber, >+ reserve_group_id => 1 >+ } >+}); >+my $reserve3 = $builder->build({ >+ source => 'Reserve', >+ value => { >+ borrowernumber => $borrowernumber, >+ reserve_group_id => 1 >+ } >+}); >+ >+is(GetReserveCount($borrowernumber), 2, 'Test borrower has 2 reserve.'); >+ >+my $reserves_group2 = $builder->build({ >+ source => 'ReserveGroup', >+ value => { >+ reserve_group_id => 2 >+ } >+}); >+my $reserve_group_id2 = $reserves_group2->{reserve_group_id}; >+ >+my $reserve4 = $builder->build({ >+ source => 'Reserve', >+ value => { >+ borrowernumber => $borrowernumber, >+ reserve_group_id => 2 >+ } >+}); >+my $reserve5 = $builder->build({ >+ source => 'Reserve', >+ value => { >+ borrowernumber => $borrowernumber, >+ reserve_group_id => 2 >+ } >+}); >+my $reserve6 = $builder->build({ >+ source => 'Reserve', >+ value => { >+ borrowernumber => $borrowernumber, >+ reserve_group_id => 2 >+ } >+}); >+ >+is(GetReserveCount($borrowernumber), 3, 'Test borrower has 2 reserve.'); >+ >+$dbh->rollback; >-- >1.7.10.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 15516
:
46392
|
47498
|
47570
|
47961
|
47962
|
47963
|
48097
|
48098
|
48448
|
48449
|
50094
|
50095
|
50096
|
53742
|
53743
|
53744
|
53770
|
53771
|
53772
|
53774
|
53775
|
53776
|
54977
|
55300
|
55304
|
55305
|
55306
|
55307
|
55308
|
55768
|
55769
|
55770
|
55771
|
55772
|
58799
|
58800
|
58801
|
58802
|
58803
|
59314
|
59315
|
59316
|
59317
|
59318
|
69902
|
69903
|
69904
|
69905
|
69906
|
72485
|
72486
|
72487
|
72488
|
72489
|
72491
|
79077
|
79078
|
79080
|
79081
|
79082
|
79083
|
79213
|
79214
|
79215
|
79216
|
79217
|
79218
|
79219
|
79220
|
79221
|
79222
|
81453
|
81454
|
81455
|
81456
|
81457
|
81458
|
81459
|
81460
|
81461
|
81462
|
81463
|
84554
|
84555
|
84556
|
84557
|
84558
|
84559
|
84560
|
84561
|
84562
|
84563
|
84564
|
87828
|
87829
|
87830
|
87831
|
87832
|
87833
|
87834
|
87835
|
87836
|
87837
|
87838
|
88038
|
88039
|
88125
|
88173
|
88174
|
88175
|
88176
|
88177
|
88178
|
88179
|
88180
|
88181
|
88182
|
88183
|
88184
|
88185
|
88186
|
90289
|
90290
|
90291
|
90292
|
90293
|
90294
|
90295
|
90296
|
90297
|
90298
|
90299
|
90300
|
90301
|
90302
|
90303
|
90829
|
90830
|
90831
|
90832
|
90833
|
90834
|
90835
|
90836
|
90837
|
90838
|
90839
|
90840
|
90841
|
90842
|
90843
|
90844
|
92783
|
92784
|
92785
|
92786
|
92787
|
92788
|
92789
|
92790
|
92791
|
92792
|
92793
|
92794
|
92795
|
92796
|
92797
|
92798
|
114513
|
114514
|
114515
|
114516
|
114517
|
114518
|
114585
|
114586
|
114603
|
114624
|
114625
|
114626
|
114627
|
114628
|
114629
|
114630
|
114631
|
114632
|
114633
|
114634
|
114635
|
114636
|
114637
|
114638
|
114639
|
114640
|
114641
|
114642
|
114643
|
114644
|
114645
|
114647
|
114648
|
114649
|
114650
|
114651
|
114652
|
114653
|
114654
|
114655
|
114656
|
114657
|
114658
|
114659
|
117423
|
117424
|
117425
|
117426
|
118281
|
118282
|
118283
|
118284
|
118285
|
118286
|
118350
|
118351
|
118352
|
118353
|
118354
|
118355
|
120368
|
120369
|
120370
|
120371
|
120372
|
120373
|
120574
|
120643
|
120644
|
120645
|
120646
|
120647
|
120648
|
120649
|
120650
|
120651
|
121523
|
121623
|
122097
|
122102
|
122627
|
128189
|
128190
|
128191
|
128192
|
128193
|
128194
|
128195
|
128196
|
128197
|
128198
|
128199
|
128200
|
128201
|
128202
|
128255
|
128256
|
128257
|
128258
|
128259
|
128260
|
128261
|
128262
|
128263
|
128264
|
128265
|
128266
|
128267
|
128268
|
128269
|
128285
|
128286
|
128287
|
128288
|
128289
|
128290
|
128291
|
128292
|
128293
|
128294
|
128295
|
128296
|
128297
|
128298
|
128299
|
138576
|
138577
|
138578
|
138579
|
138580
|
138581
|
138582
|
138583
|
138584
|
138585
|
138586
|
138587
|
138588
|
138589
|
138593
|
138594
|
138595
|
138596
|
138597
|
138738
|
138739
|
138740
|
138741
|
138742
|
138772
|
138868
|
138869
|
162076
|
162077
|
162078
|
162079
|
162080
|
162081
|
162082
|
162083
|
162084