Make checkin retargeting parts-aware
authorThomas Berezansky <tsbere@mvlc.org>
Wed, 26 Oct 2011 13:45:54 +0000 (09:45 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 14 Nov 2011 16:08:19 +0000 (11:08 -0500)
Skip part holds on copies san parts
Skip part holds for parts not on the copy
Skip title holds for copies with parts

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

index 92cc110..720bc68 100644 (file)
@@ -2343,6 +2343,11 @@ sub checkin_retarget {
 
     return if scalar(@$holds) == 0; # No holds, no retargeting
 
+    # Check for parts on this copy
+    my $parts = $self->editor->search_asset_copy_part_map({ target_copy => $self->copy->id });
+    my %parts_hash = ();
+    %parts_hash = map {$_->id, 1} @$parts if @$parts;
+
     # Loop over holds in request-ish order
     # Stage 1: Get them into request-ish order
     # Also grab type and target for skipping low hanging ones
@@ -2366,6 +2371,15 @@ sub checkin_retarget {
                 and $_->{target} != $self->copy->id);
             # Volume level, but not this volume?
             next if ($_->{hold_type} eq 'V' and $_->{target} != $self->volume->id);
+            if(@$parts) { # We have parts?
+                # Skip title holds
+                next if ($_->{hold_type} eq 'T');
+                # Skip part holds for parts not on this copy
+                next if ($_->{hold_type} eq 'P' and not $parts_hash{$_->{target}});
+            } else {
+                # No parts, no part holds
+                next if ($_->{hold_type} eq 'P');
+            }
             # So much for easy stuff, attempt a retarget!
             my $tresult = $U->storagereq('open-ils.storage.action.hold_request.copy_targeter', undef, $_->{id}, $self->copy->id);
             if(ref $tresult eq "ARRAY" and scalar @$tresult) {