Bug 10226 - suspended holds still show not available
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 27 Aug 2014 12:29:05 +0000 (08:29 -0400)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Sun, 14 Sep 2014 05:02:51 +0000 (02:02 -0300)
If you suspend a hold, the item does not show Available.  It still shows
the person next in line, who isn't eligible for the hold yet because of
the suspension.  This is not the case for a delayed hold, where you
originally place the hold and tell it not to start until a future date.
If you do that, it shows as Available.  This is confusing and
inconsistent.

Test Plan:
1) Create an item level suspended hold for a record with no other holds
2) Note in the record details that the hold shows an item level hold
3) Apply this patch
4) Refresh the record details page, note the item is "Available"
5) Optional: prove t/db_dependent/Holds.t t/db_dependent/Reserves.t

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described, passes all tests and QA script.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Reserves.pm

index d7cc334..8ecd5ca 100644 (file)
@@ -39,6 +39,7 @@ use C4::Dates qw( format_date_in_iso );
 
 use Koha::DateUtils;
 use Koha::Calendar;
+use Koha::Database;
 
 use List::MoreUtils qw( firstidx );
 
@@ -381,19 +382,33 @@ The routine does not look at future reserves (read: item level holds), but DOES
 =cut
 
 sub GetReservesFromItemnumber {
-    my ( $itemnumber ) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-    SELECT reservedate,borrowernumber,branchcode,reserve_id,waitingdate
-    FROM   reserves
-    WHERE  itemnumber=? AND ( reservedate <= CAST(now() AS date) OR
-           waitingdate IS NOT NULL )
-    ORDER BY priority
-    ";
-    my $sth_res = $dbh->prepare($query);
-    $sth_res->execute($itemnumber);
-    my ( $reservedate, $borrowernumber,$branchcode, $reserve_id, $wait ) = $sth_res->fetchrow_array;
-    return ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $wait );
+    my ($itemnumber) = @_;
+
+    my $schema = Koha::Database->new()->schema();
+
+    my $r = $schema->resultset('Reserve')->search(
+        {
+            itemnumber => $itemnumber,
+            suspend    => 0,
+            -or        => [
+                reservedate => \'<= CAST( NOW() AS DATE )',
+                waitingdate => { '!=', undef }
+            ]
+        },
+        {
+            order_by => 'priority',
+        }
+    )->first();
+
+    return unless $r;
+
+    return (
+        $r->reservedate(),
+        $r->get_column('borrowernumber'),
+        $r->get_column('branchcode'),
+        $r->reserve_id(),
+        $r->waitingdate(),
+    );
 }
 
 =head2 GetReservesFromBorrowernumber