From beabbaaf95184286ab29043680b0c3e65151af5a Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 13 Nov 2025 12:19:45 +0100 Subject: [PATCH] Bug 19814: Merge code for cud-affect_reserve and HoldsAutoFill Content-Type: text/plain; charset=utf-8 This merges two nearly identical wrappers around a call of ModReserveAffect into a new subroutine. We could reuse this subroutine in the batch checkin loop. Test plan: Verify that everything still works as expected by: - Disable HoldsAutoFill if needed. - Pick item with a hold (for current library). - Check item in via staff main page, checkin tab. - Confirm hold. - Repeat but confirm hold for another pickup library. - Enable HoldsAutoFill. - Repeat both previous checkins. There is no popup now. Signed-off-by: Marcel de Rooy --- circ/returns.pl | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/circ/returns.pl b/circ/returns.pl index b1e182b271..5caa379c19 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -114,6 +114,24 @@ for my $counter ( $query->multi_param("checkin_counter") ) { my $op = $query->param('op') // ''; +# Routine for handling the confirm hold part of cud-affect_reserve. +# Reused during batch checkin. +sub confirm_hold { + my ( $item, $hold, $diffBranchSend, $desk_id ) = @_; + + # diffBranchSend tells ModReserveAffect whether document is expected in this library or not, + # i.e., whether to apply waiting status + ModReserveAffect( $item->itemnumber, $hold->borrowernumber, $diffBranchSend, $hold->reserve_id, $desk_id ); + + if ($diffBranchSend) { + my $tobranch = $hold->pickup_library(); + + # Add transfer, enqueue if one is already in the queue, and immediately set to in transit + my $transfer = $item->request_transfer( { to => $tobranch, reason => 'Reserve', enqueue => 1 } ); + $transfer->transit; + } +} + ############ # Deal with the requests.... my $itemnumber = $query->param('itemnumber'); @@ -146,18 +164,7 @@ if ( $query->param('reserve_id') && $op eq 'cud-affect_reserve' ) { } } else { my $diffBranchSend = ( $userenv_branch ne $diffBranchReturned ) ? $diffBranchReturned : undef; - - # diffBranchSend tells ModReserveAffect whether document is expected in this library or not, - # i.e., whether to apply waiting status - ModReserveAffect( $itemnumber, $borrowernumber, $diffBranchSend, $reserve_id, $desk_id ); - - if ($diffBranchSend) { - my $tobranch = $hold->pickup_library(); - - # Add transfer, enqueue if one is already in the queue, and immediately set to in transit - my $transfer = $item->request_transfer( { to => $tobranch, reason => 'Reserve', enqueue => 1 } ); - $transfer->transit; - } + confirm_hold( $item, $hold, $diffBranchSend, $desk_id ); } } @@ -703,15 +710,8 @@ if ( $messages->{'ResFound'} ) { my $biblio = $item->biblio; my $diffBranchSend = !$branchCheck ? $reserve->{branchcode} : undef; - ModReserveAffect( $itemnumber, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id}, $desk_id ); - - if ($diffBranchSend) { - my $tobranch = Koha::Libraries->find( $reserve->{branchcode} ); - - # Add transfer, enqueue if one is already in the queue, and immediately set to in transit - my $transfer = $item->request_transfer( { to => $tobranch, reason => 'Reserve', enqueue => 1 } ); - $transfer->transit; - } + my $hold = Koha::Holds->find( $reserve->{reserve_id} ); #TODO Hold not found + confirm_hold( $item, $hold, $diffBranchSend, $desk_id ) if $hold; $template->param( hold_auto_filled => 1, -- 2.39.5