From 803186aeb70fb06bb61ed1b9c74af8cfa45cfc60 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 | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 8086db2aad..7d035a9c4d 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1962,9 +1962,13 @@ sub MoveReserve { my $item = Koha::Items->find($itemnumber); my ( $restype, $res, undef ) = CheckReserves( $item, $lookahead ); - if ( $res &&$res->{borrowernumber} == $borrowernumber) { - my $hold = Koha::Holds->find( $res->{reserve_id} ); - $hold->fill({ item_id => $itemnumber }); + if ( $res && $res->{borrowernumber} == $borrowernumber ) { + my $patron = Koha::Patrons->find($borrowernumber); + my $result = CanItemBeReserved( $patron, $item, $res->{branchcode} ); + if ( $result->{status} eq 'OK' ) { + my $hold = Koha::Holds->find( $res->{reserve_id} ); + $hold->fill({ item_id => $itemnumber }); + } } else { # The item is reserved by someone else. @@ -1987,15 +1991,23 @@ sub MoveReserve { if ( $borr_res ) { # The item is reserved by the current patron - $borr_res->fill({ item_id => $itemnumber }); - } - if ( $cancelreserve eq 'revert' ) { ## Revert waiting reserve to priority 1 - RevertWaitingStatus({ itemnumber => $itemnumber }); + my $patron = Koha::Patrons->find($borrowernumber); + my $result = CanItemBeReserved( $patron, $item, $borr_res->{branchcode} ); + if ( $result->{status} eq 'OK' ) { + # Only fill hold with actually reservable items + $borr_res->fill({ item_id => $itemnumber }); + } } - elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item - my $hold = Koha::Holds->find( $res->{reserve_id} ); - $hold->cancel; + + if ( $res ) { + if ( $cancelreserve eq 'revert' ) { ## Revert waiting reserve to priority 1 + RevertWaitingStatus({ itemnumber => $itemnumber }); + } + elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item + my $hold = Koha::Holds->find( $res->{reserve_id} ); + $hold->cancel; + } } } } -- 2.39.5