Use circ lib for finding nearest hold on renew user/tsbere/nearest_permitted_opac_renewal
authorThomas Berezansky <tsbere@mvlc.org>
Thu, 8 Mar 2012 14:25:22 +0000 (09:25 -0500)
committerThomas Berezansky <tsbere@mvlc.org>
Thu, 8 Mar 2012 14:25:22 +0000 (09:25 -0500)
This solves problems with the following situation:
    Re-use circ library for opac renewals
    Block renew if item is needed for holds
    Item is age protected
    Patron with item has home library outside of the protect range
    Patron's home library has 10+ holds the item matches

The end result is 10 holds are looked at, skipped due to age protection, and
the system decides "nope, not needed for a hold".

This does not help if the patron shows up in person at their home library,
nor does it help when not re-using the original circ library for OPAC
renewals.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index 731131d..85cec04 100644 (file)
@@ -3623,7 +3623,7 @@ sub run_renew_permit {
 
     if ($U->ou_ancestor_setting_value($self->circ_lib, 'circ.block_renews_for_holds')) {
         my ($hold, undef, $retarget) = $holdcode->find_nearest_permitted_hold(
-            $self->editor, $self->copy, $self->editor->requestor, 1
+            $self->editor, $self->copy, $self->editor->requestor, 1, $self->circ_lib
         );
         $self->push_events(new OpenILS::Event("COPY_NEEDED_FOR_HOLD")) if $hold;
     }
index 5c840c5..3ead7e6 100644 (file)
@@ -2863,11 +2863,14 @@ sub find_nearest_permitted_hold {
     my $copy   = shift;     # copy to target
     my $user   = shift;     # staff
     my $check_only = shift; # do no updates, just see if the copy could fulfill a hold
+    my $force_ou = shift;   # if set, use this OU instead of the work OU
       
     my $evt = OpenILS::Event->new('ACTION_HOLD_REQUEST_NOT_FOUND');
 
     my $bc = $copy->barcode;
 
+    $force_ou = $user->ws_ou unless $force_ou;
+
        # find any existing holds that already target this copy
        my $old_holds = $editor->search_action_hold_request(
                {       current_copy => $copy->id, 
@@ -2876,17 +2879,17 @@ sub find_nearest_permitted_hold {
                } 
        );
 
-    my $hold_stall_interval = $U->ou_ancestor_setting_value($user->ws_ou, OILS_SETTING_HOLD_SOFT_STALL);
+    my $hold_stall_interval = $U->ou_ancestor_setting_value($force_ou, OILS_SETTING_HOLD_SOFT_STALL);
 
-       $logger->info("circulator: searching for best hold at org ".$user->ws_ou.
+       $logger->info("circulator: searching for best hold at org ".$force_ou.
         " and copy $bc with a hold stalling interval of ". ($hold_stall_interval || "(none)"));
 
-       my $fifo = $U->ou_ancestor_setting_value($user->ws_ou, 'circ.holds_fifo');
+       my $fifo = $U->ou_ancestor_setting_value($force_ou, 'circ.holds_fifo');
 
        # 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", 
-               $user->ws_ou, $copy->id, 10, $hold_stall_interval, $fifo );
+               $force_ou, $copy->id, 10, $hold_stall_interval, $fifo );
 
        unless(@$best_holds) {