From e5b15f44866097b6742f0bbddc7d06d92c8527dd Mon Sep 17 00:00:00 2001
From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Date: Mon, 29 Jul 2019 09:10:04 +0100
Subject: [PATCH] Bug 23112: Update request status on return

This patch updates a request's status to RET upon return

Sponsored-by: Loughborough University
---
 C4/Circulation.pm  | 10 ++++++++++
 Koha/Illrequest.pm |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index de4dc99ed3..7a645dc88b 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -46,6 +46,7 @@ use Koha::Biblioitems;
 use Koha::DateUtils;
 use Koha::Calendar;
 use Koha::Checkouts;
+use Koha::Illrequests;
 use Koha::IssuingRules;
 use Koha::Items;
 use Koha::Patrons;
@@ -2108,6 +2109,15 @@ sub AddReturn {
         DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
     }
 
+    # Check if this item belongs to a biblio record that is attached to an
+    # ILL request, if it is we need to update the ILL request's status
+    if (C4::Context->preference('CirculateILL')) {
+        my $request = Koha::Illrequests->find(
+            { biblio_id => $item->biblio->biblionumber }
+        );
+        $request->status('RET') if $request;
+    }
+
     # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
     if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
         my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType");
diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm
index a37bc81d23..c71090f6ad 100644
--- a/Koha/Illrequest.pm
+++ b/Koha/Illrequest.pm
@@ -499,6 +499,15 @@ sub _core_status_graph {
             method         => 'check_out',
             next_actions   => [ ],
             ui_method_icon => 'fa-upload',
+        },
+        RET => {
+            prev_actions   => [ 'CHK' ],
+            id             => 'RET',
+            name           => 'Returned to library',
+            ui_method_name => 'Check in',
+            method         => 'check_in',
+            next_actions   => [ 'COMP' ],
+            ui_method_icon => 'fa-download',
         }
     };
 }
-- 
2.11.0