Bugzilla – Attachment 183304 Details for
Bug 33200
IndependentBranchesTransfers does not prevent holds from creating transfers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33200: Preventing holds from creating transfers with IndependentBranchesTransfers enabled
Bug-33200-Preventing-holds-from-creating-transfers.patch (text/plain), 4.88 KB, created by
William Lavoie
on 2025-06-17 12:33:06 UTC
(
hide
)
Description:
Bug 33200: Preventing holds from creating transfers with IndependentBranchesTransfers enabled
Filename:
MIME Type:
Creator:
William Lavoie
Created:
2025-06-17 12:33:06 UTC
Size:
4.88 KB
patch
obsolete
>From 96bb3a33b04a921ad18348d3387b788a80b367d0 Mon Sep 17 00:00:00 2001 >From: William Lavoie <william.lavoie@inLibro.com> >Date: Thu, 3 Apr 2025 11:29:39 -0400 >Subject: [PATCH] Bug 33200: Preventing holds from creating transfers with > IndependentBranchesTransfers enabled > >--- > C4/Reserves.pm | 30 +++++++++++++++++++++++++++++- > t/db_dependent/Reserves.t | 34 +++++++++++++++++++++++++++++++--- > 2 files changed, 60 insertions(+), 4 deletions(-) > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 1ffddd5b9f3..8ea43582777 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -47,6 +47,7 @@ use Koha::Library; > use Koha::Patrons; > use Koha::Plugins; > use Koha::Policy::Holds; >+use Data::Dumper; > > use List::MoreUtils qw( any ); > >@@ -875,7 +876,9 @@ sub CheckReserves { > } > > # Find this item in the reserves >- my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers ); >+ my @reserves = _Findgroupreserve( $item->biblionumber, $item->itemnumber, $lookahead_days, $ignore_borrowers); >+ # When IndependentBranchesTransfers is activate remove the reserve made from other branches >+ @reserves = _FilterHoldsForIndependentBranches( @reserves ); > > # $priority and $highest are used to find the most important item > # in the list returned by &_Findgroupreserve. (The lower $priority, >@@ -1808,6 +1811,31 @@ sub _Findgroupreserve { > return @results; > } > >+=head2 _FilterHoldsForIndependentBranches >+ >+ @reserves = &_FilterHoldsForIndependentBranches( @reserves ); >+ >+Check transfers is allowed from system preference and remove the reserves made from other branches >+ >+C<&_FilterHoldsForIndependentBranches> returns : >+C<@results> is an array of references-to-hash whose keys are mostly >+fields from the reserves table of the Koha database, plus >+ >+=cut >+ >+sub _FilterHoldsForIndependentBranches { >+ my ( @reserves) = @_; >+ if ( C4::Context->preference("IndependentBranchesTransfers") && scalar @reserves) >+ { >+ my @results; >+ foreach my $res (@reserves) { >+ push( @results, $res ) if ($res->{branchcode} eq C4::Context->userenv->{'branch'}); >+ } >+ return @results; >+ } >+ return @reserves; >+} >+ > =head2 _koha_notify_reserve > > _koha_notify_reserve( $hold->reserve_id ); >diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t >index a9224528157..ef19369c3bf 100755 >--- a/t/db_dependent/Reserves.t >+++ b/t/db_dependent/Reserves.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 70; >+use Test::More tests => 73; > use Test::MockModule; > use Test::Warn; > >@@ -61,7 +61,9 @@ my $builder = t::lib::TestBuilder->new; > > my $frameworkcode = q//; > >-t::lib::Mocks::mock_preference( 'ReservesNeedReturns', 1 ); >+ >+t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); >+t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 ); > > # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached > $dbh->do( >@@ -132,6 +134,32 @@ ok( exists( $reserve->{reserve_id} ), 'CheckReserves() include reserve_id in its > ( $status, $reserve, $all_reserves ) = CheckReserves($item); > is( $status, "Reserved", "CheckReserves Test 2" ); > >+# Set the preference 'IndependentBranchesTransfers' is set to 'yes' >+# the userenv branch and the branche code are not the same holds should be filtered >+t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 1 ); >+($status, $reserve, $all_reserves) = CheckReserves( $item ); >+is( $status, "", 'Reserves is filtered'); >+ >+# Set the userenv branchcode to be the same to the item branchcode. >+t::lib::Mocks::mock_userenv({ branchcode => $branchcode }); >+($status, $reserve, $all_reserves) = CheckReserves( $item ); >+is( $status, "Reserved", 'Reserves should not be filtered'); >+ >+t::lib::Mocks::mock_userenv({ branchcode => $branch_1 }); >+t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 ); >+my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch'); >+t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); >+ok( >+ $item->homebranch eq Koha::Policy::Holds->holds_control_library( $item, $patron ), >+ "Koha::Policy::Holds->holds_control_library returns item home branch when set to ItemHomeLibrary" >+); >+t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); >+ok( >+ $patron->branchcode eq Koha::Policy::Holds->holds_control_library( $item, $patron ), >+ "Koha::Policy::Holds->holds_control_library returns patron home branch when set to PatronLibrary" >+); >+t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch ); >+ > ### > ### Regression test for bug 10272 > ### >@@ -1533,7 +1561,7 @@ sub count_hold_print_messages { > q{ > SELECT COUNT(*) > FROM message_queue >- WHERE letter_code = 'HOLD' >+ WHERE letter_code = 'HOLD' > AND message_transport_type = 'print' > } > ); >-- >2.43.0
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 33200
:
148212
|
148484
|
148918
|
151129
|
151130
|
151348
|
151349
|
154552
|
155482
|
155483
|
155484
|
158188
|
158189
|
158190
|
171434
|
171435
|
171436
|
172707
|
172708
|
172709
|
180598
|
183302
| 183304