KMain-808 CHS report missing holds where pickup location has been changed. Modified...
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:10:05 +0000 (17:10 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: 6095afa

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

index 3808a32..1dee83d 100644 (file)
@@ -2104,6 +2104,7 @@ __PACKAGE__->register_method(
 __PACKAGE__->register_method(
     method    => 'fetch_captured_holds',
     api_name  => 'open-ils.circ.captured_holds.id_list.expired_on_shelf.retrieve',
+    
     stream    => 1,
     authoritative => 1,
     signature => q/
@@ -2148,6 +2149,8 @@ sub fetch_captured_holds {
 
     $org ||= $e->requestor->ws_ou;
 
+       $logger->info("In fetch_captured_holds VSL");
+
     my $current_copy = { '!=' => undef };
     $current_copy = { '=' => $match_copy } if $match_copy;
 
@@ -2172,12 +2175,25 @@ sub fetch_captured_holds {
         }
     };
     if($self->api_name =~ /expired/) {
+               
+               $logger->info("in if(api_name =~/expired/");
         $query->{'where'}->{'+alhr'}->{'-or'} = {
                 shelf_expire_time => { '<' => 'today'},
                 cancel_time => { '!=' => undef },
-        };
+                
+        };  
     }
     my $hold_ids = $e->json_query( $query );
+    
+     if ($self->api_name =~ /wrong_shelf/) {
+       # fetch holds whose current_shelf_lib is $org, but whose pickup 
+        # lib is some other org unit.  Ignore already-retrieved holds.
+        my $wrong_shelf =
+             pickup_lib_changed_on_shelf_holds(
+                 $e, $org, [map {$_->{id}} @$hold_ids]);
+        # match the layout of other items in $hold_ids
+       push (@$hold_ids, {id => $_}) for @$wrong_shelf;
+    }
 
     if ($self->api_name =~ /wrong_shelf/) {
         # fetch holds whose current_shelf_lib is $org, but whose pickup 
@@ -2236,7 +2252,7 @@ sub print_expired_holds_stream {
     $$params{org_id} = (defined $$params{org_id}) ? $$params{org_id}: $e->requestor->ws_ou;
 
     my @hold_ids = $self->method_lookup(
-        "open-ils.circ.captured_holds.id_list.expired_on_shelf.retrieve"
+        "open-ils.circ.captured_holds.id_list.expired_on_shelf_or_wrong_shelf.retrieve"
     )->run($auth, $params->{"org_id"});
 
     if (!@hold_ids) {
@@ -3666,7 +3682,7 @@ sub clear_shelf_process {
     my $copy_status = $U->ou_ancestor_setting_value($org_id, 'circ.holds.clear_shelf.copy_status');
 
     my @hold_ids = $self->method_lookup(
-        "open-ils.circ.captured_holds.id_list.expired_on_shelf.retrieve"
+         "open-ils.circ.captured_holds.id_list.expired_on_shelf.retrieve"
     )->run($auth, $org_id, $match_copy);
 
     $e->xact_begin;
@@ -3763,6 +3779,45 @@ sub clear_shelf_process {
         $client->respond_complete;
     }
 }
+ # returns IDs for holds that are on the holds shelf but 
+ # have had their pickup_libs change while on the shelf.
+
+
+ sub pickup_lib_changed_on_shelf_holds {
+     my $e = shift;
+   my $org_id = shift;
+    my $ignore_holds = shift;
+   $ignore_holds = [$ignore_holds] if !ref($ignore_holds);
+     my $query = {
+        select => { alhr => ['id'] },
+        from   => {
+             alhr => {
+                acp => {
+                     field => 'id',
+                    fkey  => 'current_copy'
+                 },
+             }
+        },
+        where => {
+            '+acp' => { status => OILS_COPY_STATUS_ON_HOLDS_SHELF },
+            '+alhr' => {
+                capture_time     => { "!=" => undef },
+                fulfillment_time => undef,
+                current_shelf_lib => $org_id,
+                pickup_lib => {'!='  => {'+alhr' => 'current_shelf_lib'}}
+            }
+        }
+    };
+
+     $query->{where}->{'+alhr'}->{id} =
+        {'not in' => $ignore_holds} if @$ignore_holds;
+     my $hold_ids = $e->json_query($query);
+    return [ map { $_->{id} } @$hold_ids ];
+}
+
+
 
 # returns IDs for holds that are on the holds shelf but 
 # have had their pickup_libs change while on the shelf.