From 58b080093f24173e598f5e8e61f4f4d34447c0f5 Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Mon, 4 Apr 2022 12:21:43 +0000
Subject: [PATCH] Bug 30447: Check if transfers arrived or cancelled

TO test:
 1 - Find a bib with a single item
 2 - Browse to Circulation->Transfer
 3 - Transfer the item to another branch
 4 - Check the item in at current branch and cancel the transfer on the dialog
 5 - Place a hold on the biblio for a patron at current branch
 6 - Browse to Circulation->Holds to pull
 7 - Item does not show
 8 - Apply patch, restart all
 9 - Browse to Circulation->Holds to pull
10 - Item shows

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
---
 Koha/Holds.pm           | 5 ++++-
 circ/pendingreserves.pl | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Koha/Holds.pm b/Koha/Holds.pm
index 5784cd7047..59fd35e20b 100644
--- a/Koha/Holds.pm
+++ b/Koha/Holds.pm
@@ -121,7 +121,10 @@ sub get_items_that_can_fill {
     push @bibs_or_items, 'biblionumber' => { in => \@biblionumbers } if @biblionumbers;
 
     my @branchtransfers = Koha::Item::Transfers->search(
-        { datearrived => undef },
+        {
+            datearrived => undef,
+            datecancelled => undef,
+        },
         {
             columns  => ['itemnumber'],
             collapse => 1,
diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl
index 14f0dc8983..dd6fba9e8a 100755
--- a/circ/pendingreserves.pl
+++ b/circ/pendingreserves.pl
@@ -161,7 +161,7 @@ my %where = (
     'itembib.itemlost' => 0,
     'itembib.withdrawn' => 0,
     'itembib.notforloan' => 0,
-    'itembib.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL' }
+    'itembib.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL AND datecancelled IS NULL' }
 );
 
 # date boundaries
@@ -190,6 +190,7 @@ my $holds = Koha::Holds->search(
     { %where },
     { join => 'itembib', distinct  => 1, columns => qw[me.biblionumber] }
 );
+
 my @biblionumbers = $holds->get_column('biblionumber');
 
 my $all_items;
-- 
2.20.1