From 763f003a79c20dd2cedce04612dd0c8725616223 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 13 Aug 2020 16:44:28 +0100
Subject: [PATCH] Bug 25261: (QA follow-up) Catch check in SIP Checkin

Test plan
1/ Enable the feature as per previous patches
2/ Attempt to return an item with materials attached via a SIP unit
3/ Note that the return is blocked with an alert type of '99'
4/ Signoff

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 C4/SIP/ILS/Transaction/Checkin.pm | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm
index 07797a0d4d..6a38a958ac 100644
--- a/C4/SIP/ILS/Transaction/Checkin.pm
+++ b/C4/SIP/ILS/Transaction/Checkin.pm
@@ -16,6 +16,7 @@ use C4::Debug;
 use C4::Items qw( ModItemTransfer );
 use C4::Reserves qw( ModReserveAffect );
 use Koha::DateUtils qw( dt_from_string );
+use Koha::Items;
 
 use parent qw(C4::SIP::ILS::Transaction);
 
@@ -74,8 +75,21 @@ sub do_checkin {
         $return_date = dt_from_string($return_date);
     }
 
+    my ( $return, $messages, $issue, $borrower );
+    my $item = Koha::Items->find( { barcode => $barcode } );
+    my $human_required = 0;
+    if (   C4::Context->preference("CircConfirmItemParts")
+        && defined($item)
+        && $item->materials )
+    {
+        $human_required                   = 1;
+        $messages->{additional_materials} = 1;
+    }
+
     $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
-    my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, $return_date);
+    ( $return, $messages, $issue, $borrower ) =
+      AddReturn( $barcode, $branch, undef, $return_date )
+      unless $human_required;
 
     if ( $checked_in_ok ) {
         delete $messages->{ItemLocationUpdated};
@@ -87,6 +101,9 @@ sub do_checkin {
     # biblionumber, biblioitemnumber, itemnumber
     # borrowernumber, reservedate, branchcode
     # cancellationdate, found, reservenotes, priority, timestamp
+    if ($messages->{additional_materials}) {
+        $self->alert_type('99');
+    }
     if( $messages->{DataCorrupted} ) {
         $self->alert_type('98');
     }
-- 
2.11.0