JBAS-537 Mark missing pieces in-transit items
authorBill Erickson <berickxx@gmail.com>
Mon, 5 Jun 2017 22:05:50 +0000 (18:05 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Cancel active transits before checking an item back out to the most
recent patron during mark-missing-pieces.  Otherwise, the checkout will
fail.

Commit also removes an unnecessary transaction from the first half of
the API and its associated FIXME messages.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm

index 77818e7..71dc92b 100644 (file)
@@ -1609,23 +1609,21 @@ __PACKAGE__->register_method(
 
 sub mark_item_missing_pieces {
     my( $self, $conn, $auth, $copy_id, $args ) = @_;
-    ### FIXME: We're starting a transaction here, but we're doing a lot of things outside of the transaction
-    ### FIXME: Even better, we're going to use two transactions, the first to affect pertinent holds before checkout can
-
-    my $e2 = new_editor(authtoken=>$auth, xact =>1);
-    return $e2->die_event unless $e2->checkauth;
     $args ||= {};
 
+    my $e2 = new_editor(authtoken => $auth);
+    return $e2->event unless $e2->checkauth;
+
     my $copy = $e2->retrieve_asset_copy([
         $copy_id,
         {flesh => 1, flesh_fields => {'acp' => ['call_number']}}])
-            or return $e2->die_event;
+            or return $e2->event;
 
     my $owning_lib = 
         ($copy->call_number->id == OILS_PRECAT_CALL_NUMBER) ? 
             $copy->circ_lib : $copy->call_number->owning_lib;
 
-    return $e2->die_event unless $e2->allowed('MARK_ITEM_MISSING_PIECES', $owning_lib);
+    return $e2->event unless $e2->allowed('MARK_ITEM_MISSING_PIECES', $owning_lib);
 
     #### grab the last circulation
     my $circ = $e2->search_action_circulation([
@@ -1637,7 +1635,6 @@ sub mark_item_missing_pieces {
 
     if (!$circ) {
         $logger->info('open-ils.circ.mark_item_missing_pieces: no previous checkout');
-        $e2->rollback;
         return OpenILS::Event->new('ACTION_CIRCULATION_NOT_FOUND',{'copy'=>$copy});
     }
 
@@ -1652,9 +1649,20 @@ sub mark_item_missing_pieces {
     $logger->debug("resetting holds that target the marked copy");
     OpenILS::Application::Circ::Holds->_reset_hold($e2->requestor, $_) for @$holds;
 
-    
-    if (! $e2->commit) {
-        return $e2->die_event;
+    if ($copy->status == OILS_COPY_STATUS_IN_TRANSIT) {
+        # KCLS JBAS-537 Abort active transits before attempting to
+        # check the item back out to the most recent patron.
+
+        $logger->info("Canceling active transit on mark-missing-pieces item");
+
+        my $resp = $apputils->simplereq('open-ils.circ', 
+            'open-ils.circ.transit.abort', $auth, {copyid => $copy->id});
+
+        unless ($resp && $resp == 1) {
+            $logger->error(
+                "Error canceling transit on mark-missing-pieces item");
+            return $resp;
+        }
     }
 
     my $e = new_editor(authtoken=>$auth, xact =>1);