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 <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit d95312328d)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
Nick Clemens 2023-05-18 11:09:18 +00:00 committed by Matt Blenkinsop
parent 90579d3c61
commit d322e76606

View file

@ -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) {