From 7c22f779f82b20fa3e245c68c169e9a0a4450d2f 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 Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart (cherry picked from commit 1ad0e172cddce560afcc23579948d0c4a1eca71c) Signed-off-by: Andrew Fuerste-Henry --- 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 548c6fdcf3..5df6de6696 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1842,7 +1842,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); @@ -1913,9 +1912,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 ) @@ -1977,18 +1973,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}; @@ -2005,7 +1989,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)) { @@ -2048,11 +2031,17 @@ sub searchResults { $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables); } + 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; @@ -2101,8 +2090,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 296f99cb0a..68f77b3d0b 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -131,26 +131,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 c20b1e3a60..63664c800e 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -159,7 +159,6 @@ $template->param( subscriptionsnumber => $subscriptionsnumber, ); -my $norequests = 1; my $allow_onshelf_holds; my $res = GetISBDView({ 'record' => $record, @@ -169,13 +168,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; @@ -185,6 +177,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 b22a11bea1..1734159105 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -138,19 +138,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; } @@ -386,6 +377,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 3889ab5406..c2225a69a9 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -689,7 +689,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; @@ -733,13 +732,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; @@ -843,6 +835,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.39.5