- unless ( C4::Context->preference('OPACHoldsIfAvailableAtPickup') ) {
- $canreserve = 0 if Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch })->count;
+ unless ( $can_place_hold_if_available_at_pickup ) {
+ my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
+ my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
+ my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
+ if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
+ $canreserve = 0
+ }