[open-ils-commits] r18352 - branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/SIP (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 14 18:17:56 EDT 2010


Author: erickson
Date: 2010-10-14 18:17:50 -0400 (Thu, 14 Oct 2010)
New Revision: 18352

Modified:
   branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
Log:
If an item is captured for a hold, but not in transit (i.e. on holds shelf), set the destination_location equal to the pickup library (i.e where it's supposedly on the shelf).  This is useful for autmated sorting so that the item will return to the branch whose shelf where it belongs.

Modified: branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
===================================================================
--- branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm	2010-10-14 22:17:21 UTC (rev 18351)
+++ branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm	2010-10-14 22:17:50 UTC (rev 18352)
@@ -125,13 +125,16 @@
         syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
     }
 
-    $self->{id} = $item_id;
-    $self->{copy}        = $copy;
-    $self->{volume}      = $copy->call_number;
-    $self->{record}      = $copy->call_number->record;
+    $self->{id}         = $item_id;
+    $self->{copy}       = $copy;
+    $self->{volume}     = $copy->call_number;
+    $self->{record}     = $copy->call_number->record;
     $self->{call_number} = $copy->call_number->label;
-    $self->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
+    $self->{mods}       = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
+    $self->{transit}    = $self->fetch_transit;
+    $self->{hold}       = $self->fetch_hold;
 
+
     # use the non-translated version of the copy location as the
     # collection code, since it may be used for additional routing
     # purposes by the SIP client.  Config option?
@@ -139,26 +142,12 @@
         $e->retrieve_asset_copy_location([
             $copy->location, {no_i18n => 1}])->name;
 
-    if ($copy->status->id == OILS_COPY_STATUS_IN_TRANSIT) {
-        my $transit = $e->search_action_transit_copy([
-            {
-                target_copy    => $copy->id,    # NOT barcode ($self->id)
-                dest_recv_time => undef
-            },
-            {
-                flesh => 1,
-                flesh_fields => {
-                    atc => [ 'dest' ]
-                }
-            }
-        ])->[0];
 
-        if ($transit) {
-            $self->{transit} = $transit;
-            $self->{destination_loc} = $transit->dest->shortname;
-        } else {
-            syslog('LOG_WARNING', "OILS: Item('$item_id') status is In Transit, but no action.transit_copy found!");
-        }
+    if($self->{transit}) {
+        $self->{destination_loc} = $self->{transit}->dest->shortname;
+
+    } elsif($self->{hold}) {
+        $self->{destination_loc} = $self->{hold}->pickup_lib->shortname;
     }
 
     syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
@@ -182,6 +171,71 @@
     return $self;
 }
 
+# fetch copy transit
+sub fetch_transit {
+    my $self = shift;
+    my $copy = $self->{copy} or return;
+    my $e = OpenILS::SIP->editor();
+
+    if ($copy->status->id == OILS_COPY_STATUS_IN_TRANSIT) {
+        my $transit = $e->search_action_transit_copy([
+            {
+                target_copy    => $copy->id,    # NOT barcode ($self->id)
+                dest_recv_time => undef
+            },
+            {
+                flesh => 1,
+                flesh_fields => {
+                    atc => ['dest']
+                }
+            }
+        ])->[0];
+
+        syslog('LOG_WARNING', "OILS: Item(".$copy->barcode.
+            ") status is In Transit, but no action.transit_copy found!") unless $transit;
+            
+        return $transit;
+    }
+    
+    return undef;
+}
+
+# fetch captured hold.
+# Assume transit has already beeen fetched
+sub fetch_hold {
+    my $self = shift;
+    my $copy = $self->{copy} or return;
+    my $e = OpenILS::SIP->editor();
+
+    if( ($copy->status->id == OILS_COPY_STATUS_ON_HOLDS_SHELF) ||
+        ($self->{transit} and $self->{transit}->copy_status == OILS_COPY_STATUS_ON_HOLDS_SHELF) ) {
+        # item has been captured for a hold
+
+        my $hold = $e->search_action_hold_request([
+            {
+                current_copy        => $copy->id,
+                capture_time        => {'!=' => undef},
+                cancel_time         => undef,
+                fulfillment_time    => undef
+            },
+            {
+                limit => 1,
+                flesh => 1,
+                flesh_fields => {
+                    ahr => ['pickup_lib']
+                }
+            }
+        ])->[0];
+
+        syslog('LOG_WARNING', "OILS: Item(".$copy->barcode.
+            ") is captured for a hold, but there is no matching hold request") unless $hold;
+
+        return $hold;
+    }
+
+    return undef;
+}
+
 sub run_attr_script {
 	my $self = shift;
 	return 1 if $self->{ran_script};
@@ -373,47 +427,29 @@
 sub hold_pickup_date {  
     my $self = shift;
     my $copy = $self->{copy};
+    my $hold = $self->{hold} or return 0;
 
-    if( ($copy->status->id == OILS_COPY_STATUS_ON_HOLDS_SHELF) ||
-        ($self->{transit} and $self->{transit}->copy_status == OILS_COPY_STATUS_ON_HOLDS_SHELF) ) {
+    my $date = $hold->shelf_expire_time;
 
-        # item has been captured for a hold
+    if(!$date) {
+        # hold has not hit the shelf.  create a best guess.
 
-        my $e = OpenILS::SIP->editor();
-        my $hold = $e->search_action_hold_request([
-            {
-                current_copy        => $copy->id,
-                capture_time        => {'!=' => undef},
-                cancel_time         => undef,
-                fulfillment_time    => undef
-            },
-            {limit => 1}
-        ])->[0];
-        
-        if($hold) {
-            my $date = $hold->shelf_expire_time;
+        my $interval = $shelf_expire_setting_cache{$hold->pickup_lib->id} ||
+            $U->ou_ancestor_setting_value(
+                $hold->pickup_lib->id, 
+                'circ.holds.default_shelf_expire_interval');
 
-            if(!$date) {
-                # hold has not hit the shelf.  create a best guess.
+        $shelf_expire_setting_cache{$hold->pickup_lib->id} = $interval;
 
-                my $interval = $shelf_expire_setting_cache{$hold->pickup_lib} ||
-                    $U->ou_ancestor_setting_value(
-                        $hold->pickup_lib, 
-                        'circ.holds.default_shelf_expire_interval');
-
-                $shelf_expire_setting_cache{$hold->pickup_lib} = $interval;
-
-                if($interval) {
-                    my $seconds = OpenSRF::Utils->interval_to_seconds($interval);
-                    $date = DateTime->now->add(seconds => $seconds);
-                    $date = $date->strftime('%FT%T%z') if $date;
-                }
-            }
-
-            return OpenILS::SIP->format_date($date) if $date;
+        if($interval) {
+            my $seconds = OpenSRF::Utils->interval_to_seconds($interval);
+            $date = DateTime->now->add(seconds => $seconds);
+            $date = $date->strftime('%FT%T%z') if $date;
         }
     }
 
+    return OpenILS::SIP->format_date($date) if $date;
+
     return 0;
 }
 



More information about the open-ils-commits mailing list