diff --git a/Koha/Item.pm b/Koha/Item.pm index 9f41eb16ef..854b6cfd58 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1834,7 +1834,7 @@ Return the relevant recall for this item =cut sub recall { - my ( $self ) = @_; + my ($self) = @_; my @recalls = Koha::Recalls->search( { biblio_id => $self->biblionumber, @@ -1842,11 +1842,23 @@ sub recall { }, { order_by => { -asc => 'created_date' } } )->as_list; + + my $item_level_recall; foreach my $recall (@recalls) { - if ( $recall->item_level and $recall->item_id == $self->itemnumber ){ - return $recall; + if ( $recall->item_level ) { + $item_level_recall = 1; + if ( $recall->item_id == $self->itemnumber ) { + return $recall; + } } } + if ($item_level_recall) { + + # recall needs to be filled be a specific item only + # no other item is relevant to return + return; + } + # no item-level recall to return, so return earliest biblio-level # FIXME: eventually this will be based on priority return $recalls[0]; diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index d30ea6d54b..129f63cea4 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -1920,7 +1920,7 @@ subtest 'store() tests' => sub { subtest 'Recalls tests' => sub { - plan tests => 22; + plan tests => 23; $schema->storage->txn_begin; @@ -1961,6 +1961,7 @@ subtest 'Recalls tests' => sub { )->store; is( $item1->recall->patron_id, $patron1->borrowernumber, 'Correctly returns most relevant recall' ); + is( $item2->recall, undef, 'Other items are not returned for item-level recalls' ); $recall2->set_cancelled;