mid-transit holds that are cancelled now leave the transit open and provide a warning...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 8 Dec 2006 16:09:53 +0000 (16:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 8 Dec 2006 16:09:53 +0000 (16:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6661 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 81cec08..1836a83 100644 (file)
@@ -346,6 +346,7 @@ my @AUTOLOAD_FIELDS = qw/
        old_circ
        permit_override
        pending_checkouts
+       cancelled_hold_transit
 /;
 
 
@@ -1308,17 +1309,30 @@ sub do_checkin {
                if( $hold_transit or 
                                $U->copy_status($self->copy->status)->id 
                                        == OILS_COPY_STATUS_ON_HOLDS_SHELF ) {
-                       $self->hold(
-                               ($hold_transit) ?
+
+                       my $hold = ($hold_transit) ?
                                        $self->editor->retrieve_action_hold_request($hold_transit->hold) :
-                                       $U->fetch_open_hold_by_copy($self->copy->id)
-                               );
+                                       $U->fetch_open_hold_by_copy($self->copy->id);
 
-                       $self->checkin_flesh_events;
-                       return;
+                       $self->hold($hold);
+
+                       if( $hold and $hold->cancel_time ) { # this transited hold was cancelled mid-transit
+
+                               $logger->info("circulator: we received a transit on a cancelled hold " . $hold->id);
+                               $self->reshelve_copy(1);
+                               $self->cancelled_hold_transit(1);
+                               return if $self->bail_out;
+
+                       } else {
+
+                               # hold transited to correct location
+                               $self->checkin_flesh_events;
+                               return;
+                       }
                } 
 
        } elsif( $U->copy_status($self->copy->status)->id == OILS_COPY_STATUS_IN_TRANSIT ) {
+
                $logger->warn("circulator: we have a copy ".$self->copy->barcode.
                        " that is in-transit, but there is no transit.. repairing");
                $self->reshelve_copy(1);
@@ -1340,7 +1354,6 @@ sub do_checkin {
 
    } else { # not needed for a hold
 
-
                my $circ_lib = (ref $self->copy->circ_lib) ? 
                                $self->copy->circ_lib->id : $self->copy->circ_lib;
 
@@ -1380,6 +1393,7 @@ sub do_checkin {
                $self->bail_out(1); # no need to commit anything
 
        } else {
+
                $self->push_events(OpenILS::Event->new('SUCCESS')) 
                        unless @{$self->events};
        }
@@ -1862,8 +1876,12 @@ sub checkin_flesh_events {
                $payload->{record}   = $U->record_to_mvr($self->title) if($self->title and !$self->is_precat);
                $payload->{circ}     = $self->circ;
                $payload->{transit}  = $self->transit;
-               $payload->{hold}     = $self->hold;
-               
+               $payload->{cancelled_hold_transit} = 1 if $self->cancelled_hold_transit;
+
+               # $self->hold may or may not have been replaced with a 
+               # valid hold after processing a cancelled hold
+               $payload->{hold} = $self->hold unless (not $self->hold or $self->hold->cancel_time);
+
                $evt->{payload} = $payload;
        }
 }
index 5fb6e60..14198eb 100644 (file)
@@ -455,21 +455,14 @@ sub cancel_hold {
 
                        if( $transid ) {
                                my $trans = $e->retrieve_action_transit_copy($transid);
+                               # Leave the transit alive, but  set the copy status to 
+                               # reshelving so it will be properly reshelved when it gets back home
                                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;
+                                       $trans->copy_status( OILS_COPY_STATUS_RESHELVING );
+                                       $e->update_action_transit_copy($trans) or return $e->die_event;
                                }
+                               
                        }
-
-                       # We don't want the copy to remain "in transit" or to recover 
-                       # any previous statuses
-                       $logger->info("setting copy back to reshelving in hold+transit cancel");
-                       $copy->status(OILS_COPY_STATUS_RESHELVING);
-                       $copy->editor($e->requestor->id);
-                       $copy->edit_date('now');
-                       $e->update_asset_copy($copy) or return $e->event;
                }
        }