Bug 13636 - Staff search results item status incorrect for holds
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 28 Jan 2015 13:31:30 +0000 (08:31 -0500)
committerMason James <mtj@kohaaloha.com>
Wed, 22 Apr 2015 12:08:58 +0000 (00:08 +1200)
Imagine this scenario: we have one record with four items. Two of those
items are checked out, one of those items is a waiting hold, and one of
those items is available. We would expect to see this on the search
results page. Instead, we will see both non-checked out items as
unavailable due to waiting holds.

This is due to a semantic issue GetReserveStatus.
C4::Search::searchResults uses GetReserveStatus to get the reserve
status of each item, but unlike all other calls to the sub, this one
passes in not only itemnumber, but biblionumber.

When no reserve is found for the available item, the subroutine uses the
biblionumber to grab what is essentially an arbitrary reserve to use for
the status. This makes no sense and this functionality should be
entirely removed from the subroutine so regressions like this will be
prevented in the future.

Test Plan:
1) Create one record with 4 items
   a) check two of the items out to patrons
   b) set one of the items as a waiting hold
   c) leave the fourth item as available
2) Run a search where this record will be in the results list
3) Note that the results list 2 items on loan, two unavailable
4) Apply this patch, reload the search results
5) Note that the results list 1 available, 2 on loan, 1 unavailable

Signed-off-by: John Andrews <jandrews@washoecounty.us>
Signed-off-by: Sheila Kearns <sheila.kearns@state.vt.us>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Note: This is for the staff search result list!

Works as expected.

C4/Reserves.pm
C4/Search.pm

index c6bc35f..6018383 100644 (file)
@@ -819,9 +819,9 @@ sub GetReservesForBranch {
 
 =head2 GetReserveStatus
 
-  $reservestatus = GetReserveStatus($itemnumber, $biblionumber);
+  $reservestatus = GetReserveStatus($itemnumber);
 
-Take an itemnumber or a biblionumber and return the status of the reserve places on it.
+Takes an itemnumber and returns the status of the reserve placed on it.
 If several reserves exist, the reserve with the lower priority is given.
 
 =cut
@@ -831,7 +831,7 @@ If several reserves exist, the reserve with the lower priority is given.
 ## multiple reserves for that bib can have the itemnumber set
 ## the sub is only used once in the codebase.
 sub GetReserveStatus {
-    my ($itemnumber, $biblionumber) = @_;
+    my ($itemnumber) = @_;
 
     my $dbh = C4::Context->dbh;
 
@@ -842,12 +842,6 @@ sub GetReserveStatus {
         ($found, $priority) = $sth->fetchrow_array;
     }
 
-    if ( $biblionumber and not defined $found and not defined $priority ) {
-        $sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE biblionumber = ? order by priority LIMIT 1");
-        $sth->execute($biblionumber);
-        ($found, $priority) = $sth->fetchrow_array;
-    }
-
     if(defined $found) {
         return 'Waiting'  if $found eq 'W' and $priority == 0;
         return 'Finished' if $found eq 'F';
index 4f022a5..9bc2933 100644 (file)
@@ -2003,7 +2003,7 @@ sub searchResults {
                     #        should map transit status to record indexed in Zebra.
                     #
                     ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers($item->{itemnumber});
-                    $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber}, $oldbiblio->{biblionumber} );
+                    $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} );
                 }
 
                 # item is withdrawn, lost, damaged, not for loan, reserved or in transit