Bugzilla – Attachment 138739 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: Relevant controller changes and tests
Bug-15516-Relevant-controller-changes-and-tests.patch (text/plain), 14.37 KB, created by
Michal Denar
on 2022-08-06 19:12:04 UTC
(
hide
)
Description:
Bug 15516: Relevant controller changes and tests
Filename:
MIME Type:
Creator:
Michal Denar
Created:
2022-08-06 19:12:04 UTC
Size:
14.37 KB
patch
obsolete
>From 0a52881c150911971955ba92f581a4ec7920f3ce Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Mon, 1 Mar 2021 15:25:52 +1300 >Subject: [PATCH] Bug 15516: Relevant controller changes and tests > >Signed-off-by: Michal Denar <black23@gmail.com> >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> > >Signed-off-by: Michal Denar <black23@gmail.com> >--- > C4/Reserves.pm | 48 ++++++++++++------- > Koha/Hold.pm | 28 +++++++++++ > Koha/HoldGroup.pm | 63 +++++++++++++++++++++++++ > Koha/HoldGroups.pm | 60 ++++++++++++++++++++++++ > Koha/Holds.pm | 26 +++++++++++ > t/db_dependent/Koha/Holds.t | 72 ++++++++++++++++++++++++++++- > t/db_dependent/Reserves/HoldGroup.t | 53 +++++++++++++++++++++ > 7 files changed, 333 insertions(+), 17 deletions(-) > create mode 100644 Koha/HoldGroup.pm > create mode 100644 Koha/HoldGroups.pm > create mode 100755 t/db_dependent/Reserves/HoldGroup.t > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index d5e01f283d..6a5b688776 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -193,6 +193,7 @@ sub AddReserve { > my $found = $params->{found}; > my $itemtype = $params->{itemtype}; > my $non_priority = $params->{non_priority}; >+ my $hold_group_id = $params->{hold_group_id}; > > $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' }) > or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); >@@ -255,6 +256,7 @@ sub AddReserve { > itemtype => $itemtype, > item_level_hold => $checkitem ? 1 : 0, > non_priority => $non_priority ? 1 : 0, >+ hold_group_id => $hold_group_id, > } > )->store(); > $hold->set_waiting() if $found && $found eq 'W'; >@@ -520,18 +522,18 @@ sub CanItemBeReserved { > biblionumber => $item->biblionumber, > }; > $search_params->{found} = undef if $params->{ignore_found_holds}; >- my $holds = Koha::Holds->search($search_params); >- return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record } if $holds->count() >= $holds_per_record; >+ my $holds_count = Koha::Holds->count_holds($search_params); >+ return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record } if $holds_count >= $holds_per_record; > } > } > > if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '') > { >- my $today_holds = Koha::Holds->search({ >+ my $today_holds_count = Koha::Holds->count_holds({ > borrowernumber => $patron->borrowernumber, > reservedate => dt_from_string->date > }); >- return { status => 'tooManyReservesToday', limit => $holds_per_day } if $today_holds->count() >= $holds_per_day; >+ return { status => 'tooManyReservesToday', limit => $holds_per_day } if $today_holds_count >= $holds_per_day; > } > > # we check if it's ok or not >@@ -1235,6 +1237,9 @@ sub ModReserveAffect { > > $hold->itemnumber($itemnumber); > >+ my @reserve_ids; >+ push @reserve_ids, $hold->reserve_id; >+ > if ($transferToDo) { > $hold->set_transfer(); > } elsif (C4::Context->preference('HoldsNeedProcessingSIP') >@@ -1247,6 +1252,15 @@ sub ModReserveAffect { > # Complete transfer if one exists > my $transfer = $hold->item->get_transfer; > $transfer->receive if $transfer; >+ >+ # if this hold was part of a group, cancel other holds in the group >+ if ( $hold->hold_group_id ) { >+ my @holds = $hold->hold_group->holds->as_list; >+ foreach my $h ( @holds ) { >+ push @reserve_ids, $h->reserve_id; >+ $h->cancel unless $h->reserve_id == $hold->reserve_id; >+ } >+ } > } > > _koha_notify_hold_changed( $hold ) if $notify_library; >@@ -1258,18 +1272,20 @@ sub ModReserveAffect { > CartToShelf( $itemnumber ); > } > >- my $std = $dbh->prepare(q{ >- DELETE q, t >- FROM tmp_holdsqueue q >- INNER JOIN hold_fill_targets t >- ON q.borrowernumber = t.borrowernumber >- AND q.biblionumber = t.biblionumber >- AND q.itemnumber = t.itemnumber >- AND q.item_level_request = t.item_level_request >- AND q.holdingbranch = t.source_branchcode >- WHERE t.reserve_id = ? >- }); >- $std->execute($hold->reserve_id); >+ foreach my $id ( @reserve_ids ) { >+ my $std = $dbh->prepare(q{ >+ DELETE q, t >+ FROM tmp_holdsqueue q >+ INNER JOIN hold_fill_targets t >+ ON q.borrowernumber = t.borrowernumber >+ AND q.biblionumber = t.biblionumber >+ AND q.itemnumber = t.itemnumber >+ AND q.item_level_request = t.item_level_request >+ AND q.holdingbranch = t.source_branchcode >+ WHERE t.reserve_id = ? >+ }); >+ $std->execute($id); >+ } > > logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold ) > if C4::Context->preference('HoldsLog'); >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 63e30970ca..80866e02c4 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -41,6 +41,7 @@ use Koha::Plugins; > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > > use Koha::Exceptions; >+use Koha::HoldGroups; > use Koha::Exceptions::Hold; > > use base qw(Koha::Object); >@@ -796,6 +797,14 @@ sub fill { > C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self ) > if C4::Context->preference('HoldsLog'); > >+ # if this hold was part of a group, cancel other holds in the group >+ if ( $self->hold_group_id ) { >+ my @holds = $self->hold_group->holds->as_list; >+ foreach my $h ( @holds ) { >+ $h->cancel unless $h->reserve_id == $self->id; >+ } >+ } >+ > Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( > { > biblio_ids => [ $old_me->biblionumber ] >@@ -861,6 +870,25 @@ sub _set_default_expirationdate { > dt_from_string( $self->reservedate )->add( $timeunit => $period ) ); > } > >+=head3 hold_group >+ >+ my $hold_group = $hold->hold_group; >+ my $hold_group_id = $hold_group->id if $hold_group; >+ >+Return the Koha::HoldGroup object of a hold if part of a hold group >+ >+=cut >+ >+sub hold_group { >+ my ( $self ) = @_; >+ >+ if ( $self->hold_group_id ) { >+ return Koha::HoldGroups->find( $self->hold_group_id ); >+ } >+ >+ return; >+} >+ > =head3 _move_to_old > > my $is_moved = $hold->_move_to_old; >diff --git a/Koha/HoldGroup.pm b/Koha/HoldGroup.pm >new file mode 100644 >index 0000000000..08675c48eb >--- /dev/null >+++ b/Koha/HoldGroup.pm >@@ -0,0 +1,63 @@ >+package Koha::HoldGroup; >+ >+# Copyright 2020 Koha Development team >+# >+# 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, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::HoldGroup - Koha Hold Group object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 holds >+ >+ $holds = $hold_group->holds >+ >+Return all holds associated with this group >+ >+=cut >+ >+sub holds { >+ my ($self) = @_; >+ >+ my $holds_rs = $self->_result->reserves->search; >+ return Koha::Holds->_new_from_dbic($holds_rs); >+} >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'HoldGroup'; >+} >+ >+=head1 AUTHORS >+ >+Josef Moravec <josef.moravec@gmail.com> >+ >+=cut >+ >+1; >diff --git a/Koha/HoldGroups.pm b/Koha/HoldGroups.pm >new file mode 100644 >index 0000000000..ad96b60704 >--- /dev/null >+++ b/Koha/HoldGroups.pm >@@ -0,0 +1,60 @@ >+package Koha::HoldGroups; >+ >+# Copyright Koha Development team 2020 >+# >+# 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, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use Koha::HoldGroup; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::HoldGroups - Koha Hold Group object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'HoldGroup'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::HoldGroup'; >+} >+ >+=head1 AUTHOR >+ >+Josef Moravec <josef.moravec@gmail.com> >+ >+=cut >+ >+1; >diff --git a/Koha/Holds.pm b/Koha/Holds.pm >index 4ff90e679e..4450c21fc4 100644 >--- a/Koha/Holds.pm >+++ b/Koha/Holds.pm >@@ -178,6 +178,32 @@ sub filter_out_has_cancellation_requests { > { join => 'cancellation_requests' } ); > } > >+=head3 count >+ >+ $holds->count( $search_params ); >+ >+This overwrites the default count(). >+ >+Return the number of holds, where a hold group is counted as one hold. >+ >+=cut >+ >+sub count_holds { >+ my ( $self, $search_params ) = @_; >+ >+ $search_params = { >+ hold_group_id => undef, >+ }; >+ my $holds_without_group_count = $self->search( $search_params )->count(); >+ >+ $search_params = { >+ hold_group_id => { '!=', undef }, >+ }; >+ my $hold_groups_count = $self->search( $search_params, { group_by => 'me.hold_group_id' })->count(); >+ >+ return $holds_without_group_count + $hold_groups_count; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t >index aec261dd1f..4706ba22f6 100755 >--- a/t/db_dependent/Koha/Holds.t >+++ b/t/db_dependent/Koha/Holds.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 9; > use Test::Warn; > > use C4::Circulation qw( AddIssue ); >@@ -641,6 +641,76 @@ subtest 'set_waiting+patron_expiration_date' => sub { > }; > }; > >+subtest 'count_holds' => sub { >+ plan tests => 3; >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ >+ class => 'Koha::Patrons', >+ }); >+ my $patron_id = $patron->borrowernumber; >+ >+ my $hold1 = $builder->build_object({ >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_id, >+ hold_group_id => undef, >+ }, >+ }); >+ >+ is($patron->holds->count_holds, 1, 'Test patron has 1 hold.'); >+ >+ my $hold_group = $builder->build_object({ >+ class => 'Koha::HoldGroups', >+ }); >+ >+ my $hold2 = $builder->build_object({ >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_id, >+ hold_group_id => $hold_group->hold_group_id, >+ } >+ }); >+ my $hold3 = $builder->build_object({ >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_id, >+ hold_group_id => $hold_group->hold_group_id, >+ } >+ }); >+ >+ is($patron->holds->count_holds, 2, 'Test patron has 2 holds.'); >+ >+ my $hold_group2 = $builder->build_object({ >+ class => 'Koha::HoldGroups', >+ }); >+ >+ my $hold4 = $builder->build_object({ >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_id, >+ hold_group_id => $hold_group2->hold_group_id, >+ } >+ }); >+ my $hold5 = $builder->build_object({ >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_id, >+ hold_group_id => $hold_group2->hold_group_id, >+ } >+ }); >+ my $hold6 = $builder->build_object({ >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron_id, >+ hold_group_id => $hold_group2->hold_group_id, >+ } >+ }); >+ >+ is($patron->holds->count_holds, 3, 'Test patron has 3 holds.'); >+ >+ $schema->storage->txn_rollback; >+}; > > $schema->storage->txn_rollback; > >diff --git a/t/db_dependent/Reserves/HoldGroup.t b/t/db_dependent/Reserves/HoldGroup.t >new file mode 100755 >index 0000000000..4bc4687c79 >--- /dev/null >+++ b/t/db_dependent/Reserves/HoldGroup.t >@@ -0,0 +1,53 @@ >+#!/usr/bin/perl >+ >+# Copyright 2020 Koha Development team >+# >+# 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, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'holds tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $hold_group = $builder->build_object({ class => 'Koha::HoldGroups' }); >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ hold_group_id => $hold_group->hold_group_id, >+ } >+ } >+ ); >+ >+ my $holds = $hold_group->holds; >+ is( ref($holds), 'Koha::Holds', 'Right type' ); >+ my $hold_from_group = $holds->next; >+ is( $hold_from_group->id, $hold->id, 'Right object' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.30.2
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