From be375ed01ce997817b23bbd219b05033ac1c35e7 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 6 Sep 2023 00:13:48 +0000 Subject: [PATCH] Bug 34722: Prevent other items from displaying to fill item-level recalls This patch prevents other items attached to a record from being displayed as 'recalled' by item-level recalls. To test: 1. Ensure UseRecalls system preference is enabled and circulation rules relevant to recalls are configured. Set 'on shelf recalls allowed' circulation rule 'if any unavailable' for ease of testing. 2. Search for a record that has multiple items, or create one with multiple items. Check out two of the items (Item A and Item B) to a patron, Patron A. 3. Log into the OPAC as another patron, Patron B. Search for the record and place a recall. Choose to recall a specific item and select Item A. 4. Go back to the staff interface and view the catalogue detail page for the record. Notice that every item has a 'recalled by...' message, even though Item A was specifically recalled. 5. Log into the OPAC as another patron, Patron C. Search for the record and place a recall. Choose to recall a specific item, notice every item has a 'recalled by...' message. Select Item B and Confirm. 6. In your terminal, the 'Other items are not returned for item-level recalls' test should fail when running prove t/db_dependent/Koha/Item.t 7. Apply the patch and restart services 8. Confirm tests at t/db_dependent/Koha/Item.t now pass 9. Refresh the staff interface, confirm only Items A and B have the recalled message and the recall patron information for each item is accurate 10. Log into the OPAC as another patron, Patron D. Search for the record and place a recall. Choose to recall a specific item. Confirm only Items A and B have the recalled message. Sponsored-by: Toi Ohomai Institute of Technology Signed-off-by: David Nind Signed-off-by: Katrin Fischer Perltidied new code. Signed-off-by: Tomas Cohen Arazi --- Koha/Item.pm | 18 +++++++++++++++--- t/db_dependent/Koha/Item.t | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) 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; -- 2.39.5