@@ -, +, @@ B) on the same record, both for pickup at the logged-in library in the command line: - In a ktd shell prompt, open the db client with koha-mysql kohadev - UPDATE reserves SET expirationdate = DATE_SUB(CURDATE(), INTERVAL 1 DAY) WHERE borrowernumber = "holds waiting past their expiration date" tab (do not check in the book) --> Note that Patron B's hold is now an item-level hold and does not have a waiting status library, and one for Patron B at a different library --> Note that Patron B's hold is now an item-level hold, and there is no "Revert transit status" button B) on the same record, both for pickup at the logged-in library hold is already waiting --> A new modal will pop up to fill Patron B's hold --> Note that Patron B's hold is now an item-level hold and does not have a waiting status --> Note that Patron B's hold is still a bib-level/"next available" hold --> Note that Patron B's hold is still a bib-level/"next available" hold --> Note that Patron B's hold is still a bib-level/"next available" hold library, and one for Patron B at a different library hold is already waiting --> A new modal will pop up to fill Patron B's hold --> Confirm that the information on the slip is correct --> Confirm that the hold is correctly put in transit --> Confirm the information on the slip is correct --> Confirm the hold is correctly assigned and set to waiting --> Confirm the information on the slip is correct --> Confirm the hold is correctly put in transit --> Confirm the information on the slip is correct --> Confirm the hold is correctly assigned and set to waiting --> Confirm a correct hold slip pops up for Patron B's hold --> Confirm that Patron B's hold is correctly put in transit B) on the same record, both for pickup at the logged-in library --> Confirm a correct hold slip pops up for Patron B's hold --> Confirm Patron B's hold is correctly set to Waiting --> Tests pass --- C4/Reserves.pm | 66 +++++++----------------------------- circ/returns.pl | 25 +++++++++----- t/db_dependent/Circulation.t | 8 +++-- 3 files changed, 35 insertions(+), 64 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -106,7 +106,6 @@ BEGIN { GetReserveStatus - GetOtherReserves ChargeReserveFee GetReserveFee @@ -714,55 +713,6 @@ sub CanReserveBeCanceledFromOpac { return $reserve->is_cancelable_from_opac; } -=head2 GetOtherReserves - - ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber); - -Check queued list of this document and check if this document must be transferred - -=cut - -sub GetOtherReserves { - my ($itemnumber) = @_; - my $messages; - my $nextreservinfo; - my $item = Koha::Items->find($itemnumber); - my ( undef, $checkreserves, undef ) = CheckReserves($item); - if ($checkreserves) { - if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) { - $messages->{'transfert'} = $checkreserves->{'branchcode'}; - #minus priorities of others reservs - ModReserveMinusPriority( - $itemnumber, - $checkreserves->{'reserve_id'}, - ); - - #launch the subroutine dotransfer - C4::Items::ModItemTransfer( - $itemnumber, - $item->holdingbranch, - $checkreserves->{'branchcode'}, - 'Reserve' - ), - ; - } - - #step 2b : case of a reservation on the same branch, set the waiting status - else { - $messages->{'waiting'} = 1; - ModReserveMinusPriority( - $itemnumber, - $checkreserves->{'reserve_id'}, - ); - ModReserveStatus($itemnumber,'W'); - } - - $nextreservinfo = $checkreserves; - } - - return ( $messages, $nextreservinfo ); -} - =head2 ChargeReserveFee $fee = ChargeReserveFee( $borrowernumber, $fee, $title ); @@ -1298,7 +1248,7 @@ sub ModReserveAffect { ($messages,$nextreservinfo) = &ModReserveCancelAll($itemnumber,$borrowernumber,$reason); -function to cancel reserv,check other reserves, and transfer document if it's necessary +function to cancel reserve and check other reserves =cut @@ -1306,14 +1256,24 @@ sub ModReserveCancelAll { my $messages; my $nextreservinfo; my ( $itemnumber, $borrowernumber, $cancellation_reason ) = @_; + my $item = Koha::Items->find($itemnumber); #step 1 : cancel the reservation my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber }); return unless $holds->count; $holds->next->cancel({ cancellation_reason => $cancellation_reason }); - #step 2 launch the subroutine of the others reserves - ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); + #step 2 check for other reserves on this item + ( undef, $nextreservinfo, undef ) = CheckReserves($item); + + if ($nextreservinfo) { + if( $item->holdingbranch ne $nextreservinfo->{'branchcode'} ) { + $messages->{'transfert'} = $nextreservinfo->{'branchcode'}; + } + else { + $messages->{'waiting'} = 1; + } + } return ( $messages, $nextreservinfo->{borrowernumber} ); } --- a/circ/returns.pl +++ a/circ/returns.pl @@ -41,7 +41,7 @@ use C4::Items qw( ModItemTransfer ); use C4::Members::Messaging; use C4::Members; use C4::Output qw( output_html_with_http_headers ); -use C4::Reserves qw( ModReserve ModReserveAffect GetOtherReserves ); +use C4::Reserves qw( ModReserve ModReserveAffect CheckReserves ); use C4::RotatingCollections; use Koha::AuthorisedValues; use Koha::BiblioFrameworks; @@ -162,15 +162,21 @@ if ( $query->param('reserve_id') && $op eq 'cud-affect_reserve') { } # FIXME else? } 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) { + ModItemTransfer( $itemnumber, $userenv_branch, $diffBranchSend, 'Reserve' ); + } } -# check if we have other reserves for this document, if we have a return send the message of transfer - my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); + # check if we have other reserves for this document, if we have a result send the message of transfer + # FIXME do we need to do this if we didn't take the cancel_reserve branch above? + my ( undef, $nextreservinfo, undef ) = CheckReserves($item); - my $patron = Koha::Patrons->find( $nextreservinfo ); - if ( $messages->{'transfert'} ) { + my $patron = Koha::Patrons->find( $nextreservinfo->{'borrowernumber'} ); + if ( $userenv_branch ne $nextreservinfo->{'branchcode'} ) { $template->param( itemtitle => $biblio->title, itembiblionumber => $biblio->biblionumber, @@ -595,15 +601,18 @@ if ( $messages->{'ResFound'} ) { my $diffBranchSend = !$branchCheck ? $reserve->{branchcode} : undef; ModReserveAffect( $itemnumber, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id}, $desk_id ); - my ( $messages, $nextreservinfo ) = GetOtherReserves($reserve->{itemnumber}); + + if ($diffBranchSend) { + ModItemTransfer( $itemnumber, $item->holdingbranch, $reserve->{branchcode}, 'Reserve' ); + } $template->param( hold_auto_filled => 1, print_slip => C4::Context->preference('HoldsAutoFillPrintSlip'), - reserve_id => $nextreservinfo->{reserve_id}, + reserve_id => $reserve->{reserve_id}, ); - if ( $messages->{'transfert'} ) { + if ($diffBranchSend) { $template->param( itemtitle => $biblio->title, itembiblionumber => $biblio->biblionumber, --- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -37,7 +37,7 @@ use C4::Circulation qw( AddIssue AddReturn CanBookBeRenewed GetIssuingCharges Ad use C4::Biblio; use C4::Items qw( ModItemTransfer ); use C4::Log; -use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll ModReserveAffect CheckReserves GetOtherReserves ); +use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll ModReserveAffect CheckReserves ); use C4::Overdues qw( CalcFine UpdateFine get_chargeable_units ); use C4::Members::Messaging qw( SetMessagingPreference ); use Koha::DateUtils qw( dt_from_string output_pref ); @@ -5976,8 +5976,10 @@ subtest 'Checkout should correctly terminate a transfer' => sub { ModItemTransfer( $item->itemnumber, $library_1->branchcode, $library_2->branchcode, 'Manual' ); ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id ); - GetOtherReserves( $item->itemnumber ) - ; # To put the Reason, it's what does returns.pl... + ModItemTransfer( + $item->itemnumber, $library_1->branchcode, + $library_2->branchcode, 'Reserve' + ); # To put the Reason, it's what does returns.pl... my $hold = Koha::Holds->find($reserve_id); is( $hold->found, 'T', 'Hold is in transit' ); my $transfer = $item->get_transfer; --