From 3e78a908f0fb7c904ab478d1c4f8ede4bab3c9ba Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 27 Aug 2014 08:29:05 -0400 Subject: [PATCH] Bug 10226 - suspended holds still show not available 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 Signed-off-by: Katrin Fischer Works as described, passes all tests and QA script. Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- C4/Reserves.pm | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index d7cc3346be..8ecd5caebe 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -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