More CancelRequestItem functionality for NCIP::ILS::Evergreen.
authorJason Stephenson <jstephenson@mvlc.org>
Tue, 3 Nov 2015 16:21:19 +0000 (11:21 -0500)
committerJason Stephenson <jstephenson@mvlc.org>
Tue, 3 Nov 2015 16:31:31 +0000 (11:31 -0500)
Now, with abort transit action!

The cancelrequestitem message handler can optionally abort the hold
transit, if any.  To activate this feature, add a section like:

<holds>
  <abort_transit_on_cancel/>
</holds>

to your oils_ncip.xml configuration file inside the man <ncip>
element.  See examples/oils_ncip.xml.example.

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

index 01fb8e9..95b240d 100644 (file)
         reminder to the person that edits the configuration.
     -->
   </patrons>
+  <holds>
+    <!--
+       If you want to have transits aborted when holds are canceled
+       via CancelRequestItem, then move the following chunk out of
+       this comment:
+
+        <abort_transit_on_cancel/>
+    -->
+  </holds>
 </ncip>
index db97d70..27e10b7 100644 (file)
@@ -1118,6 +1118,13 @@ sub cancelrequestitem {
     }
 
     if ($hold) {
+        # If there is a transit, abort it.  NOTE: We do this before
+        # canceling to avoid negative consequences of retargeting and
+        # in case the reset of the hold done by the transit abort ever
+        # messes with cancel_time, etc.
+        if ($hold->transit() && $self->{abort_transit_on_hold_cancel}) {
+            $self->abort_transit($hold->transit());
+        }
         my $result = $self->cancel_hold($hold);
         if (ref($result)) {
             $response->problem(_problem_from_event("Temporary Processing Failure", $result));
@@ -2351,6 +2358,31 @@ sub cancel_hold {
     return $r;
 }
 
+=head2 abort_transit
+
+    $result = $ils->abort_transit($transit);
+
+This method aborts the passed in transit and returns true or false if
+it succeeded.  In general, we don't care about the return value here,
+but subclasses might.
+
+=cut
+
+sub abort_transit {
+    my $self = shift;
+    my $transit = shift;
+    my $result = $U->simplereq(
+        'open-ils.circ',
+        'open-ils.circ.transit.abort',
+        $self->{session}->{authtoken},
+        {transitid => $transit->id()}
+    );
+    if (ref($result)) {
+        return 0;
+    }
+    return 1;
+}
+
 =head2 create_hold_note
 
     $note = $ils->create_hold_note($hold, $title, $body);
@@ -2396,9 +2428,9 @@ sub create_hold_note {
     $hold = $ils->find_hold_via_note($title, $body);
 
 Searches for a hold based on a note title and note body.  Returns the
-note if found, undef otherwise.  The search is limited to unfulfilled,
-uncanceled hold where the request_lib equals the NCIPServer working
-org. unit.
+hold, and fleshes its transit (if any), if found, undef otherwise.
+The search is limited to unfulfilled, uncanceled hold where the
+request_lib equals the NCIPServer working org. unit.
 
 =cut
 
@@ -2426,7 +2458,7 @@ sub find_hold_via_note {
         'open-ils.pcrud.search.ahrn',
         $self->{session}->{authtoken},
         $search,
-        {flesh => 1, flesh_fields => {ahrn => ['hold']}}
+        {flesh => 2, flesh_fields => {ahrn => ['hold'], ahr => ['transit']}}
     );
     if (ref($note) eq 'Fieldmapper::action::hold_request_note') {
         return $note->hold();
@@ -2709,6 +2741,15 @@ sub _init {
         my ($stat) = grep {$_->id() == $entry->{stat_cat}} @$stat_cats;
         push(@{$self->{stat_cat_entries}}, grep {$_->owner() =~ $re && $_->value() eq $entry->{content}} @{$stat->entries()});
     }
+
+    # Check if we should abort transits on request cancellation.  We
+    # put this in a different variable because someone may not have
+    # updated their configuration since this feature was added and we
+    # don't want runtime errors.
+    $self->{abort_transit_on_hold_cancel} = 0;
+    if ($self->{config}->{holds} && $self->{config}->{holds}->{abort_transit_on_cancel}) {
+        $self->{abort_transit_on_hold_cancel} = 1;
+    }
 }
 
 # Search for holds using the user, idvalue and selection_ou.