deleting transits on canceled or retargeted holds
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 10 Sep 2006 05:09:25 +0000 (05:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 10 Sep 2006 05:09:25 +0000 (05:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6046 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Transit.pm

index 2e7f970..21cb016 100644 (file)
@@ -27,6 +27,7 @@ use OpenILS::Utils::CStoreEditor q/:funcs/;
 use OpenILS::Utils::PermitHold;
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Const qw/:const/;
+use OpenILS::Application::Circ::Transit;
 
 my $apputils = "OpenILS::Application::AppUtils";
 my $U = $apputils;
@@ -442,6 +443,24 @@ sub cancel_hold {
                        $copy->editor($e->requestor->id);
                        $copy->edit_date('now');
                        $e->update_asset_copy($copy) or return $e->event;
+
+               } elsif( $copy->status == OILS_COPY_STATUS_IN_TRANSIT ) {
+
+                       my $hid = $hold->id;
+                       # We don't want the copy to remain "in transit"
+                       $copy->status(OILS_COPY_STATUS_RESHELVING);
+                       $logger->warn("! canceling hold [$hid] that is in transit");
+                       my $transid = $e->search_action_hold_transit_copy({hold=>$hold->id},{idlist=>1})->[0];
+
+                       if( $transid ) {
+                               my $trans = $e->retrieve_action_transit_copy($transid);
+                               if( $trans ) {
+                                       $logger->info("Aborting transit [$transid] on hold [$hid] cancel...");
+                                       my $evt = OpenILS::Application::Circ::Transit::__abort_transit($e, $trans, $copy, 1);
+                                       $logger->info("Transit abort completed with result $evt");
+                                       return $evt unless "$evt" eq 1;
+                               }
+                       }
                }
        }
 
@@ -839,6 +858,8 @@ sub _reset_hold {
 
        $logger->info("reseting hold ".$hold->id);
 
+       my $hid = $hold->id;
+
        if( $hold->capture_time and $hold->current_copy ) {
 
                my $copy = $e->retrieve_asset_copy($hold->current_copy)
@@ -852,8 +873,21 @@ sub _reset_hold {
                        $e->update_asset_copy($copy) or return $e->event;
 
                } elsif( $copy->status == OILS_COPY_STATUS_IN_TRANSIT ) {
-                       $logger->warn("reseting hold that is in transit: ".$hold->id);
-                       # is this allowed?      
+
+                       # We don't want the copy to remain "in transit"
+                       $copy->status(OILS_COPY_STATUS_RESHELVING);
+                       $logger->warn("! reseting hold [$hid] that is in transit");
+                       my $transid = $e->search_action_hold_transit_copy({hold=>$hold->id},{idlist=>1})->[0];
+
+                       if( $transid ) {
+                               my $trans = $e->retrieve_action_transit_copy($transid);
+                               if( $trans ) {
+                                       $logger->info("Aborting transit [$transid] on hold [$hid] reset...");
+                                       my $evt = OpenILS::Application::Circ::Transit::__abort_transit($e, $trans, $copy, 1);
+                                       $logger->info("Transit abort completed with result $evt");
+                                       return $evt unless "$evt" eq 1;
+                               }
+                       }
                }
        }
 
@@ -861,7 +895,6 @@ sub _reset_hold {
        $hold->clear_current_copy;
 
        $e->update_action_hold_request($hold) or return $e->event;
-
        $e->commit;
 
        $U->storagereq(
index fffc01f..796ce43 100644 (file)
@@ -179,7 +179,6 @@ sub abort_transit {
 
        my $copy;
        my $transit;
-       my $hold;
        my $evt;
 
        my $e = new_editor(xact => 1, authtoken => $authtoken);
@@ -213,6 +212,18 @@ sub abort_transit {
        }
        # ---------------------------------------------------------------------
 
+       return __abort_transit( $e, $transit, $copy );
+}
+
+
+
+sub __abort_transit {
+
+       my( $e, $transit, $copy, $no_reset_hold ) = @_;
+
+       my $evt;
+       my $hold;
+
        if( $transit->copy_status == OILS_COPY_STATUS_LOST or
                $transit->copy_status == OILS_COPY_STATUS_MISSING ) {
                $e->rollback;
@@ -238,7 +249,7 @@ sub abort_transit {
        $e->commit;
 
        # if this is a hold transit, un-capture/un-target the hold
-       if($holdtransit) {
+       if($holdtransit and !$no_reset_hold) {
                $hold = $e->retrieve_action_hold_request($holdtransit->hold)
                        or return $e->event;
                $evt = $holdcode->_reset_hold( $e->requestor, $hold );