@@ -, +, @@ rules $ kshell t/db_dependent/Reserves.t --- C4/Reserves.pm | 63 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 8 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -331,6 +331,35 @@ sub CanBookBeReserved{ return { status =>'alreadypossession' }; } + if ( $params->{itemtype} + and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) + { + # biblio-level, item type-contrained + my $patron = Koha::Patrons->find($borrowernumber); + my $reservesallowed = Koha::CirculationRules->get_effective_rule( + { + itemtype => $params->{itemtype}, + categorycode => $patron->categorycode, + branchcode => $pickup_branchcode, + rule_name => 'reservesallowed', + } + )->rule_value; + my $count = $patron->holds->search( + { + '-or' => [ + { 'me.itemtype' => $params->{itemtype} }, + { 'item.itype' => $params->{itemtype} } + ] + }, + { + join => ['item'] + } + )->count; + + return { status => '' } + unless $reservesallowed > $count; + } + my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); #get items linked via host records my @hostitems = get_hostitemnumbers_of($biblionumber); @@ -485,17 +514,35 @@ sub CanItemBeReserved { $querycount .= "AND ( $branchfield = ? OR $branchfield IS NULL )"; - # If using item-level itypes, fall back to the record - # level itemtype if the hold has no associated item - $querycount .= - C4::Context->preference('item-level_itypes') - ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?" - : " AND biblioitems.itemtype = ?" - if defined $ruleitemtype; + if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) { + if ( C4::Context->preference('item-level_itypes') ) { + $querycount .= q{ + AND ( COALESCE( items.itype, biblioitems.itemtype ) = ? + OR reserves.itemtype = ? ) + }; + } + else { + $querycount .= q{ + AND ( biblioitems.itemtype = ? + OR reserves.itemtype = ? ) + }; + } + } + elsif ( defined $ruleitemtype ) { + # If using item-level itypes, fall back to the record + # level itemtype if the hold has no associated item + $querycount .= + C4::Context->preference('item-level_itypes') + ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?" + : " AND biblioitems.itemtype = ?"; + } my $sthcount = $dbh->prepare($querycount); - if ( defined $ruleitemtype ) { + if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) { + $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype, $ruleitemtype ); + } + elsif ( defined $ruleitemtype ) { $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype ); } else { --