LP#1464709 Hold targeter / pull list uses is_available
authorBill Erickson <berickxx@gmail.com>
Thu, 27 Aug 2015 21:44:14 +0000 (17:44 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 27 Aug 2015 21:47:18 +0000 (17:47 -0400)
Holds targeter and pull list generator treat copies with an
is_available=true status the same as "available" and "reshelving".

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm

index 8011b9a..d2ddcd6 100644 (file)
@@ -5616,6 +5616,7 @@ SELECT  usr,
                        ahcm_1.copy_count AS potential_copies
                FROM action.hold_request ahr
                JOIN asset.copy acp ON (acp.id = ahr.current_copy)
+               JOIN config.copy_status ccs ON (ccs.id = acp.status)
                JOIN asset.call_number acn ON (acp.call_number = acn.id)
                JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id)
                JOIN asset.call_number_suffix acns ON (acn.suffix = acns.id)
@@ -5651,7 +5652,7 @@ SELECT  usr,
                        ahr.cancel_time IS NULL AND
                        csp.id IS NULL AND
                        (ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
-                       acp.status IN (0,7)
+                       ccs.is_available
                ]]></oils_persist:source_definition>
                <fields oils_persist:primary="id">
                        <field reporter:label="Status" name="status" oils_persist:virtual="true" />
index 3d592d6..3bc6f4c 100644 (file)
@@ -760,7 +760,9 @@ sub hold_pull_list {
     my $count = 1 if ($self->api_name =~/count$/o);
 
     my $status_filter = '';
-    $status_filter = 'AND a.status IN (0,7)' if ($self->api_name =~/status_filtered/o);
+    $status_filter = 
+        'AND a.status IN ((SELECT id FROM config.copy_status WHERE is_available))' 
+        if ($self->api_name =~/status_filtered/o);
 
     my $select = <<"    SQL";
         SELECT  h.*
@@ -1094,6 +1096,9 @@ sub new_hold_copy_targeter {
     $self->{target_weight} = {};
     $self->{max_loops} = {};
 
+    my %avail_statuses = map { $_->id => 1 } 
+        @{asset::copy_status->search_where({is_available => 't'})};
+
     my $holds;
 
     try {
@@ -1427,11 +1432,12 @@ sub new_hold_copy_targeter {
             # reset prox list after trimming good copies
             $prox_list = create_prox_list(
                 $self, $pu_lib,
-                [ grep { $_->status == 0 || $_->status == 7 } @good_copies ],
+                [ grep { exists($avail_statuses{$_->status}) } @good_copies ],
                 $hold, $hold_copy_map
             );
 
-            $all_copies = [ grep { ''.$_->circ_lib ne $pu_lib && ( $_->status == 0 || $_->status == 7 ) } @good_copies ];
+            $all_copies = [ grep { ''.$_->circ_lib ne $pu_lib && 
+                exists($avail_statuses{$_->status}) } @good_copies ];
 
             my $min_prox = [ sort keys %$prox_list ]->[0];
             my $best;
@@ -1708,6 +1714,9 @@ sub reservation_targeter {
 
     my $reservations;
 
+    my %avail_statuses = map { $_->id => 1 } 
+        @{asset::copy_status->search_where({is_available => 't'})};
+
     try {
         if ($one_reservation) {
             $self->method_lookup('open-ils.storage.transaction.begin')->run( $client );
@@ -1809,7 +1818,7 @@ sub reservation_targeter {
                     next;
                 }
 
-                if ($copy->status->id == 0 || $copy->status->id == 7) {
+                if (exists($avail_statuses{$copy->status->id})) {
                     push @good_resources, $res;
                     next;
                 }