From 0ea078c6b16c2ecf369166ecfbedde6bfaf0e651 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 22 Jun 2021 15:49:45 +0200 Subject: [PATCH] Bug 3142: Use filter_by_for_holds where holdability is calculated Signed-off-by: Martin Renvoize --- C4/Search.pm | 25 ++++++------------------- Koha/Holds.pm | 17 ++--------------- opac/opac-ISBDdetail.pl | 10 ++-------- opac/opac-MARCdetail.pl | 10 +--------- opac/opac-detail.pl | 9 +-------- 5 files changed, 12 insertions(+), 59 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 5cf7e0ae90..0da4b3ddf0 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1781,7 +1781,6 @@ sub searchResults { my $itembinding_count = 0; my $itemdamaged_count = 0; my $item_in_transit_count = 0; - my $can_place_holds = 0; my $item_onhold_count = 0; my $notforloan_count = 0; my $items_count = scalar(@fields); @@ -1852,9 +1851,6 @@ sub searchResults { $onloan_items->{$key}->{longoverdue}++; $longoverdue_count++; } - else { # can place holds as long as item isn't lost - $can_place_holds = 1; - } } # items not on loan, but still unavailable ( lost, withdrawn, damaged ) @@ -1916,18 +1912,6 @@ sub searchResults { $item_onhold_count++ if $reservestatus eq 'Waiting'; $item->{status} = ($item->{withdrawn}//q{}) . "-" . ($item->{itemlost}//q{}) . "-" . ($item->{damaged}//q{}) . "-" . ($item->{notforloan}//q{}); - # can place a hold on a item if - # not lost nor withdrawn - # not damaged unless AllowHoldsOnDamagedItems is true - # item is either for loan or on order (notforloan < 0) - $can_place_holds = 1 - if ( - !$item->{itemlost} - && !$item->{withdrawn} - && ( !$item->{damaged} || C4::Context->preference('AllowHoldsOnDamagedItems') ) - && ( !$item->{notforloan} || $item->{notforloan} < 0 ) - ); - $other_count++; my $key = $prefix . $item->{status}; @@ -1944,7 +1928,6 @@ sub searchResults { } # item is available else { - $can_place_holds = 1; $available_count++; $available_items->{$prefix}->{count}++ if $item->{$hbranch}; foreach (qw(branchname itemcallnumber description)) { @@ -2001,11 +1984,17 @@ sub searchResults { ); } + my $biblio_object = Koha::Biblios->find( $oldbiblio->{biblionumber} ); + $oldbiblio->{biblio_object} = $biblio_object; + + my $can_place_holds = 1; # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either if (!C4::Context->preference("item-level_itypes")) { if ($itemtype && $itemtype->{notforloan}) { $can_place_holds = 0; } + } else { + $can_place_holds = $biblio_object->items->filter_by_for_hold()->count; } $oldbiblio->{norequests} = 1 unless $can_place_holds; $oldbiblio->{items_count} = $items_count; @@ -2054,8 +2043,6 @@ sub searchResults { $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount; } - $oldbiblio->{biblio_object} = Koha::Biblios->find( $oldbiblio->{biblionumber} ); - push( @newresults, $oldbiblio ); } diff --git a/Koha/Holds.pm b/Koha/Holds.pm index fdc492b0ce..6885b4d6bf 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -130,26 +130,13 @@ sub get_items_that_can_fill { } ); - my @hold_not_allowed_itypes = Koha::CirculationRules->search( - { - rule_name => 'holdallowed', - branchcode => undef, - categorycode => undef, - rule_value => 'not_allowed', - } - )->get_column('itemtype'); - return Koha::Items->search( { biblionumber => { in => \@biblionumbers }, - itemlost => 0, - withdrawn => 0, - notforloan => 0, - onloan => undef, itemnumber => { -not_in => [ @branchtransfers, @waiting_holds ] }, - itype => { -not_in => \@hold_not_allowed_itypes }, + onloan => undef, } - ); + )->filter_by_for_hold(); } =head3 type diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 47fcb5e852..dada1a2744 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -167,7 +167,6 @@ $template->param( subscriptionsnumber => $subscriptionsnumber, ); -my $norequests = 1; my $allow_onshelf_holds; my $res = GetISBDView({ 'record' => $record, @@ -177,13 +176,6 @@ my $res = GetISBDView({ my $items = $biblio->items; while ( my $item = $items->next ) { - $norequests = 0 - if $norequests - && !$item->withdrawn - && !$item->itemlost - && ($item->notforloan < 0 || not $item->notforloan ) - && !Koha::ItemTypes->find($item->effective_itemtype)->notforloan - && $item->itemnumber; $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) unless $allow_onshelf_holds; @@ -193,6 +185,8 @@ if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_item $template->param( ReservableItems => 1 ); } +my $norequests = ! $items->filter_by_for_hold->count; + $template->param( RequestOnOpac => C4::Context->preference("RequestOnOpac"), norequests => $norequests, diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 69578be6aa..4d9b5efbf3 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -143,19 +143,10 @@ $template->param( ) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible. $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8; # except -8; -my $norequests = 1; my $allow_onshelf_holds; my $items = $biblio->items; while ( my $item = $items->next ) { - $norequests = 0 - if $norequests - && !$item->withdrawn - && !$item->itemlost - && ($item->notforloan < 0 || not $item->notforloan ) - && !Koha::ItemTypes->find($item->effective_itemtype)->notforloan - && $item->itemnumber; - $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) unless $allow_onshelf_holds; } @@ -391,6 +382,7 @@ if( C4::Context->preference('ArticleRequests') ) { $template->param( artreqpossible => $artreqpossible ); } +my $norequests = ! $biblio->items->filter_by_for_hold->count; $template->param( item_loop => \@item_loop, item_header_loop => \@item_header_loop, diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 0860aa487a..fb9247d83d 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -668,7 +668,6 @@ if ( $show_holds_count || $show_priority) { } $template->param( show_priority => $has_hold ) ; -my $norequests = 1; my %itemfields; my (@itemloop, @otheritemloop); my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef; @@ -712,13 +711,6 @@ if ( not $viewallitems and @items > $max_items_to_display ) { my $item = Koha::Items->find( $itm->{itemnumber} ); $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; $itm->{priority} = $priority{ $itm->{itemnumber} }; - $norequests = 0 - if $norequests - && !$itm->{'withdrawn'} - && !$itm->{'itemlost'} - && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'}) - && !$itemtypes->{$itm->{'itype'}}->{notforloan} - && $itm->{'itemnumber'}; $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) unless $allow_onshelf_holds; @@ -805,6 +797,7 @@ if( C4::Context->preference('ArticleRequests') ) { $template->param( artreqpossible => $artreqpossible ); } +my $norequests = ! $biblio->items->filter_by_for_hold->count; $template->param( MARCNOTES => $marcnotesarray, norequests => $norequests, -- 2.20.1