diff --git a/Koha/Holds.pm b/Koha/Holds.pm index 7c6d5b9f50..3b8b92d790 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -161,11 +161,18 @@ sub get_items_that_can_fill { collapse => 1, } )->get_column('itemnumber'); + my @pending_recalls = Koha::Recalls->search( + { 'status' => [ 'waiting', 'in_transit' ] }, + { + columns => ['item_id'], + collapse => 1, + } + )->get_column('item_id'); return Koha::Items->search( { -or => \@bibs_or_items, - itemnumber => { -not_in => [ @branchtransfers, @waiting_holds ] }, + itemnumber => { -not_in => [ @branchtransfers, @waiting_holds, @pending_recalls ] }, onloan => undef, notforloan => 0, } diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index 40dd2b3206..5114de678e 100755 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -808,7 +808,7 @@ subtest 'Desks' => sub { }; subtest 'get_items_that_can_fill' => sub { - plan tests => 6; + plan tests => 7; Koha::CirculationRules->search( { @@ -913,6 +913,16 @@ subtest 'get_items_that_can_fill' => sub { [ $item_2->itemnumber, $item_5->itemnumber ], 'Only item 2 and 5 are available for filling the hold' ); + my $waiting_recall = $builder->build_object( + { class => 'Koha::Recalls', value => { item_id => $item_5->itemnumber, status => 'waiting' } } ); + $items = $holds->get_items_that_can_fill; + is_deeply( + [ map { $_->itemnumber } $items->as_list ], + [ $item_2->itemnumber ], + 'Only item 2 is available for filling the hold as item 5 is allocated to a pending recall' + ); + $waiting_recall->delete; + # Marking item_5 is no hold allowed Koha::CirculationRule->new( {