From 086cd3cd11db7b2f1847ffc79da37ffc4b748e11 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 18 May 2023 11:09:18 +0000 Subject: [PATCH] Bug 33761: Alter query to remove items with active transfers from available list Current code removes all items without an active transfer, and any with completed transfers. This patch moves the conditionals for transfers into the join, then adds a new condition to remove items with active transfers. To test: 1 - Apply unit test patch only 2 - prove -v t/db_dependent/HoldsQueue.t 3 - It fails 4 - Apply second patch 5 - prove -v t/db_dependent/HoldsQueue.t 6 - Success! Signed-off-by: Martin Renvoize --- C4/HoldsQueue.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 2beb38afe0..4884f6570e 100644 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -326,13 +326,14 @@ sub GetItemsAvailableToFillHoldRequestsForBib { $items_query .= "JOIN biblioitems USING (biblioitemnumber) LEFT JOIN itemtypes USING (itemtype) "; } - $items_query .= " LEFT JOIN branchtransfers ON (items.itemnumber = branchtransfers.itemnumber)"; + $items_query .= " LEFT JOIN branchtransfers ON ( + items.itemnumber = branchtransfers.itemnumber + AND branchtransfers.datearrived IS NULL AND branchtransfers.datecancelled IS NULL + )"; $items_query .= " WHERE items.notforloan = 0 AND holdingbranch IS NOT NULL AND itemlost = 0 AND withdrawn = 0"; - $items_query .= " AND branchtransfers.datearrived IS NULL - AND branchtransfers.datecancelled IS NULL"; $items_query .= " AND damaged = 0" unless C4::Context->preference('AllowHoldsOnDamagedItems'); $items_query .= " AND items.onloan IS NULL AND (itemtypes.notforloan IS NULL OR itemtypes.notforloan = 0) @@ -343,7 +344,8 @@ sub GetItemsAvailableToFillHoldRequestsForBib { AND itemnumber IS NOT NULL AND (found IS NOT NULL OR priority = 0) ) - AND items.biblionumber = ?"; + AND items.biblionumber = ? + AND branchtransfers.itemnumber IS NULL"; my @params = ($biblionumber, $biblionumber); if ($branches_to_use && @$branches_to_use) { -- 2.40.1