Hold current_shelf_lib API for setting/clearing.
authorBill Erickson <berick@esilibrary.com>
Tue, 27 Dec 2011 18:18:08 +0000 (13:18 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 4 Jan 2012 19:40:00 +0000 (14:40 -0500)
Sets and clears the hold.current_shelf_lib value as appropriate during
hold capture, transit checkin, hold resetting, etc.

Also, we now create hold transits (instead of regular transits) when a
captured copy is (unexpectedly) found at the wrong branch and needs to
transit to the pickup lib.  This can happen if the captured copy simply
transits to the wrong place (existing behavior) or the pickup lib for
the hold was changed while the copy was on the shelf (new behavior).

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index 50ef6d6..406bd24 100644 (file)
@@ -1655,6 +1655,7 @@ sub handle_checkout_holds {
         $hold->clear_capture_time;
         $hold->clear_shelf_time;
         $hold->clear_shelf_expire_time;
+           $hold->clear_current_shelf_lib;
 
         return $self->bail_on_event($e->event)
             unless $e->update_action_hold_request($hold);
@@ -2798,23 +2799,42 @@ sub checkin_build_copy_transit {
     my $self            = shift;
     my $dest            = shift;
     my $copy       = $self->copy;
-   my $transit    = Fieldmapper::action::transit_copy->new;
+    my $transit    = Fieldmapper::action::transit_copy->new;
+
+    # if we are transiting an item to the shelf shelf, it's a hold transit
+    if (my $hold = $self->remote_hold) {
+        $transit = Fieldmapper::action::hold_transit_copy->new;
+        $transit->hold($hold->id);
+
+        # the item is going into transit, remove any shelf-iness
+        if ($hold->current_shelf_lib or $hold->shelf_time) {
+            $hold->clear_current_shelf_lib;
+            $hold->clear_shelf_time;
+            return $self->bail_on_events($self->editor->event)
+                unless $self->editor->update_action_hold_request($hold);
+        }
+    }
 
     #$dest  ||= (ref($copy->circ_lib)) ? $copy->circ_lib->id : $copy->circ_lib;
     $logger->info("circulator: transiting copy to $dest");
 
-   $transit->source($self->circ_lib);
-   $transit->dest($dest);
-   $transit->target_copy($copy->id);
-   $transit->source_send_time('now');
-   $transit->copy_status( $U->copy_status($copy->status)->id );
+    $transit->source($self->circ_lib);
+    $transit->dest($dest);
+    $transit->target_copy($copy->id);
+    $transit->source_send_time('now');
+    $transit->copy_status( $U->copy_status($copy->status)->id );
 
     $logger->debug("circulator: setting copy status on transit: ".$transit->copy_status);
 
-    return $self->bail_on_events($self->editor->event)
-        unless $self->editor->create_action_transit_copy($transit);
+    if ($self->remote_hold) {
+        return $self->bail_on_events($self->editor->event)
+            unless $self->editor->create_action_hold_transit_copy($transit);
+    } else {
+        return $self->bail_on_events($self->editor->event)
+            unless $self->editor->create_action_transit_copy($transit);
+    }
 
-   $copy->status(OILS_COPY_STATUS_IN_TRANSIT);
+    $copy->status(OILS_COPY_STATUS_IN_TRANSIT);
     $self->update_copy;
     $self->checkin_changed(1);
 }
@@ -3171,6 +3191,7 @@ sub put_hold_on_shelf {
     my($self, $hold) = @_;
 
     $hold->shelf_time('now');
+    $hold->current_shelf_lib($self->circ_lib);
 
     my $shelf_expire = $U->ou_ancestor_setting_value(
         $self->circ_lib, 'circ.holds.default_shelf_expire_interval', $self->editor);
index 6705d61..d35e13d 100644 (file)
@@ -672,6 +672,7 @@ sub uncancel_hold {
     $hold->clear_capture_time;
     $hold->clear_prev_check_time;
     $hold->clear_shelf_expire_time;
+       $hold->clear_current_shelf_lib;
 
     $e->update_action_hold_request($hold) or return $e->die_event;
     $e->commit;
@@ -1796,6 +1797,7 @@ sub _reset_hold {
        $hold->clear_current_copy;
        $hold->clear_shelf_time;
        $hold->clear_shelf_expire_time;
+       $hold->clear_current_shelf_lib;
 
        $e->update_action_hold_request($hold) or return $e->die_event;
        $e->commit;