Rework clear_hold_shelf process so that it looks for eligible holds for the cleared...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 14 Apr 2010 16:22:50 +0000 (16:22 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 14 Apr 2010 16:22:50 +0000 (16:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16236 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 6141c61..f2b1886 100644 (file)
@@ -1883,7 +1883,7 @@ sub find_nearest_permitted_hold {
 
        # search for what should be the best holds for this copy to fulfill
        my $best_holds = $U->storagereq(
-               "open-ils.storage.action.hold_request.nearest_hold.atomic",
+        "open-ils.storage.action.hold_request.nearest_hold.atomic", 
                $user->ws_ou, $copy->id, 10, $hold_stall_interval );
 
        unless(@$best_holds) {
@@ -2217,7 +2217,7 @@ sub clear_shelf_process {
 
         my $copy = $hold->current_copy;
 
-        if($copy_status) {
+        if($copy_status or $copy_status == 0) {
             # if a clear-shelf copy status is defined, update the copy
             $copy->status($copy_status);
             $copy->edit_date('now');
@@ -2225,50 +2225,59 @@ sub clear_shelf_process {
             $e->update_asset_copy($copy) or return $e->die_event;
         }
 
-        my ($alt_hold) = __PACKAGE__->find_nearest_permitted_hold($e, $copy, $e->requestor, 1);
+        push(@holds, $hold);
+    }
 
-        if($alt_hold) {
+    if ($e->commit) {
 
-            # copy is needed for a hold
-            $client->respond({action => 'hold', copy => $copy, hold_id => $hold->id});
+        for my $hold (@holds) {
 
-        } elsif($copy->circ_lib != $e->requestor->ws_ou) {
+            my $copy = $hold->current_copy;
 
-            # copy needs to transit
-            $client->respond({action => 'transit', copy => $copy, hold_id => $hold->id});
+            my ($alt_hold) = __PACKAGE__->find_nearest_permitted_hold($e, $copy, $e->requestor, 1);
 
-        } else {
+            if($alt_hold) {
+
+                # copy is needed for a hold
+                $client->respond({action => 'hold', copy => $copy, hold_id => $hold->id});
 
-            # copy needs to go back to the shelf
-            $client->respond({action => 'shelf', copy => $copy, hold_id => $hold->id});
+            } elsif($copy->circ_lib != $e->requestor->ws_ou) {
+
+                # copy needs to transit
+                $client->respond({action => 'transit', copy => $copy, hold_id => $hold->id});
+
+            } else {
+
+                # copy needs to go back to the shelf
+                $client->respond({action => 'shelf', copy => $copy, hold_id => $hold->id});
+            }
         }
 
-        push(@holds, $hold);
-    }
+        # tell the client we're done
+        $client->respond_complete;
 
-    $e->commit;
+        # fire off the hold cancelation trigger
+        my $trigger = OpenSRF::AppSession->connect('open-ils.trigger');
 
-    # tell the client we're done
-    $client->respond_complete;
+        for my $hold (@holds) {
 
-    # fire off the hold cancelation trigger
-    my $trigger = OpenSRF::AppSession->connect('open-ils.trigger');
+            my $req = $trigger->request(
+                'open-ils.trigger.event.autocreate', 
+                'hold_request.cancel.expire_holds_shelf', 
+                $hold, $org_id);
 
-    for my $hold (@holds) {
+            # wait for response so don't flood the service
+            $req->recv;
+        }
 
-        my $req = $trigger->request(
-            'open-ils.trigger.event.autocreate', 
-            'hold_request.cancel.expire_holds_shelf', 
-            $hold, $org_id);
+        $trigger->disconnect;
 
-        # wait for response so don't flood the service
-        $req->recv;
+    } else {
+        # tell the client we're done
+        $client->respond_complete;
     }
-
-    $trigger->disconnect;
 }
 
-
 __PACKAGE__->register_method(
     method    => 'usr_hold_summary',
     api_name  => 'open-ils.circ.holds.user_summary',