From 31a86589046ce62b85b8016fffc19207264be4d4 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 11 Sep 2025 11:58:26 +0200 Subject: [PATCH] Bug 40792: Do not fill holds with non-reservable items. Verify that the item issued is reservable before filling the patron's hold. 1. Go to circulation and fine rules and add a rule for an itemtype that can be issued, for instance "Maps" in koha-testing-docker, with 0 in the column "Holds per record (count)". 2. Go to any biblio where there are items that may be reserved. Create an item with the above created item type and give it a barcode, e.g., 'tempbarcode'. 3. Place a hold for any patron (for instance 23529000120056 in koha-testing-docker). 4. Issue the item 'tempbarcode' to the patron with the hold. 5. Make sure the hold remains. 6. Create a new hold to another borrower (for instance 23529000197047), and make sure this new hold has priority 2. 7. Return the item 'tempbarcode' and issue it to the second patron. 8. Make sure both holds remain. --- C4/Reserves.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 84957f1179..0cc122eefc 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2182,8 +2182,11 @@ sub MoveReserve { my ( $restype, $res, undef ) = CheckReserves( $item, $lookahead ); if ( $res && $res->{borrowernumber} == $patron->borrowernumber ) { - my $hold = Koha::Holds->find( $res->{reserve_id} ); - $hold->fill( { item_id => $item->id } ); + my $result = CanItemBeReserved( $patron, $item, $res->{branchcode} ); + if ( $result->{status} eq 'OK' ) { + my $hold = Koha::Holds->find( $res->{reserve_id} ); + $hold->fill( { item_id => $item->id } ); + } } else { # The item is reserved by someone else. @@ -2207,14 +2210,21 @@ sub MoveReserve { if ($hold) { # The item is reserved by the current patron - $hold->fill( { item_id => $item->id } ); + my $result = CanItemBeReserved( $patron, $item, $hold->branchcode ); + if ( $result->{status} eq 'OK' ) { + + # Only fill hold with actually reservable items + $hold->fill( { item_id => $item->id } ); + } } - $hold = Koha::Holds->find( $res->{reserve_id} ); - if ( $cancelreserve eq 'revert' ) { - $hold->revert_found(); - } elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item - $hold->cancel; + if ($res) { + $hold = Koha::Holds->find( $res->{reserve_id} ); + if ( $cancelreserve eq 'revert' ) { + $hold->revert_found(); + } elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item + $hold->cancel; + } } } } -- 2.39.5