Make some changes to NCIP::ILS::Evergreen->check_circ_details.
authorJason Stephenson <jstephenson@mvlc.org>
Fri, 9 Oct 2015 17:57:17 +0000 (13:57 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 19 Oct 2015 20:14:40 +0000 (16:14 -0400)
Testing revealed some problems with the initial logic.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
lib/NCIP/ILS/Evergreen.pm

index 65712bc..1a5f3c3 100644 (file)
@@ -413,7 +413,7 @@ sub checkinitem {
     # the patron was provided, that it is checked out to the patron in
     # question. We also verify the copy ownership and circulation
     # location.
-    my $problem = $self->check_circ_details($circ, $copy, $user);
+    my $problem = $self->check_circ_details($details, $user);
     if ($problem) {
         # We need to fill in some information, however.
         if (!$problem->ProblemValue() && !$problem->ProblemElement()) {
@@ -1745,13 +1745,14 @@ sub check_user_for_problems {
 
 =head2 check_circ_details
 
-    $problem = $ils->check_circ_details($circ, $copy, $user);
+    $problem = $ils->check_circ_details($details, $user);
 
 Checks if we can checkin or renew a circulation. That is, the
 circulation is still open (i.e. the copy is still checked out), if we
 either own the copy or are the circulation location, and if the
-circulation is for the optional $user argument. $circ and $copy are
-required. $user is optional.
+circulation is for the optional $user argument. The $details argument
+is required and comes from the retrieve_copy_details call. $user is
+optional.
 
 Returns a problem if any of the above conditions fail. Returns undef
 if they pass and we can proceed with the checkin or renewal.
@@ -1765,12 +1766,21 @@ fields will be empty and need to be filled in by the caller.
 =cut
 
 sub check_circ_details {
-    my ($self, $circ, $copy, $user) = @_;
+    my ($self, $details, $user) = @_;
+
+    my $copy = $details->{copy};
+    my $circ = $details->{circ};
+    my $transit = $details->{transit};
 
     # Shortcut for the next check.
     my $ou_id = $self->{session}->{work_ou}->id();
 
-    if (!$circ || $circ->checkin_time() || ($circ->circ_lib() != $ou_id && $copy->circ_lib() != $ou_id)) {
+    # We need to have a circulation.  The copy needs to either have
+    # been checked out at the NCIP user's working_ou or it needs to be
+    # owned there.  If the circulation was subsequently checked in,
+    # then we need an open transit to the NCIP user's working_ou.
+    if (!$circ || ($circ->circ_lib() != $ou_id && $copy->circ_lib() != $ou_id)
+            || ($circ->checkin_time() && (!$transit || $transit->dest() != $ou_id))) {
         # Item isn't checked out.
         return NCIP::Problem->new(
             {