diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 6df7ff8341..2ace2048fb 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3069,18 +3069,10 @@ sub CanBookBeRenewed { return ( 0, "on_reserve" ) if ( $item->current_holds->search( { non_priority => 0 } )->count ); - my $fillable_holds = Koha::Holds->search( - { - biblionumber => $item->biblionumber, - non_priority => 0, - found => undef, - reservedate => { '<=' => \'NOW()' }, - suspend => 0 - } - ); - if ( $fillable_holds->count ) { + + my ($status, $matched_reserve, $fillable_holds) = CheckReserves($item); + if ( $fillable_holds ) { if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailable') ) { - my @possible_holds = $fillable_holds->as_list; # Get all other items that could possibly fill reserves # FIXME We could join reserves (or more tables) here to eliminate some checks later @@ -3090,14 +3082,12 @@ sub CanBookBeRenewed { notforloan => 0, -not => { itemnumber => $item->itemnumber } })->as_list; - return ( 0, "on_reserve" ) if @possible_holds && (scalar @other_items < scalar @possible_holds); + return ( 0, "on_reserve" ) if @{$fillable_holds} && (scalar @other_items < scalar @{$fillable_holds} ); my %matched_items; - foreach my $possible_hold (@possible_holds) { + foreach my $possible_hold ( @{$fillable_holds} ) { my $fillable = 0; - my $patron_with_reserve = Koha::Patrons->find($possible_hold->borrowernumber); - - # FIXME: We are not checking whether the item we are renewing can fill the hold + my $patron_with_reserve = Koha::Patrons->find($possible_hold->{borrowernumber}); foreach my $other_item (@other_items) { next if defined $matched_items{$other_item->itemnumber}; @@ -3115,7 +3105,6 @@ sub CanBookBeRenewed { } } else { - my ($status, $matched_reserve, $possible_reserves) = CheckReserves($item); return ( 0, "on_reserve" ) if $status; } } diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index f35af9d754..5e88a29a00 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -4457,12 +4457,9 @@ subtest 'ItemsDeniedRenewal rules are checked' => sub { } ); - my $allow_book = $builder->build_object({ class => 'Koha::Items', value => { + my $allow_book = $builder->build_sample_item({ homebranch => $idr_lib->branchcode, - withdrawn => 0, - itype => 'NOHIDE', - location => 'NOPROC' - } + holdingbranch => $idr_lib->branchcode, }); my $idr_borrower = $builder->build_object({ class => 'Koha::Patrons', value=> {