From 6f2044972aab1eaa355cfb091fca97dd64d86502 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Mon, 21 Nov 2016 18:54:40 +0000
Subject: [PATCH] Bug 17665 - SIP2 Item Information Response returns incorrect
 circulation status of '08' ( waiting on hold shelf ) if record has any holds
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=utf-8

If a record has any holds on it, the SIP2 item information response will
return a value of 08 "waiting on hold shelf" even if the item is not
actually a waiting hold. This is clearly a bug.

Test Plan:
1) Find an item that is not a waiting hold, but whose record has one or
   more holds.
2) Issue a SIP2 item information request
3) Note in the response, the circulation status field is '08'
4) Apply this patch
5) Repeat the item informationr request
6) Note the code is now '03' ( available )
7) Check the item in to fill the hold
8) Repeat the item information request
9) Verify the circulation status is now '08'

Followed test plan, works as expected
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 C4/SIP/ILS/Item.pm | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm
index 3329497..0649799 100644
--- a/C4/SIP/ILS/Item.pm
+++ b/C4/SIP/ILS/Item.pm
@@ -240,13 +240,15 @@ sub title_id {
 
 sub sip_circulation_status {
     my $self = shift;
-    if ($self->{patron}) {
-		return '04';    # charged
-    } elsif (scalar @{$self->{hold_queue}}) {
-		return '08';    # waiting on hold shelf
-    } else {
-		return '03';    # available
-    }                   # FIXME: 01-13 enumerated in spec.
+    if ( $self->{patron} ) {
+        return '04';    # charged
+    }
+    elsif ( grep { $_->{itemnumber} == $self->{itemnumber}  } @{ $self->{hold_shelf} } ) {
+        return '08';    # waiting on hold shelf
+    }
+    else {
+        return '03';    # available
+    }    # FIXME: 01-13 enumerated in spec.
 }
 
 sub sip_security_marker {
-- 
2.1.4