'Opportunistic' Acq In-process Copy Overlay
authorDan Wells <dbw2@calvin.edu>
Fri, 6 Sep 2013 20:36:47 +0000 (16:36 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 16 Sep 2013 17:02:31 +0000 (13:02 -0400)
It is both normal and common to overlay brief acquisitions bib
records with more complete records, and it is simple to create
copies as part of the overlay process, but there is no *simple* way
to have the imported copies overlay the acq copies.

This code builds off the existing copy overlay code (which matches
and overlays using specified IDs), but uses broader matching criteria.
By selecting the new option, "Auto Overlay In-process Acquisitions
Copies", the system will potentially overlay copies which:
  * have associated lineitem details (that is, they were created
    by the acquisitions process), and
  * that lineitem detail has the same owning_lib as the incoming
    copy's owning_lib
  * the current copy associated with that lineitem detail is "In
    process"

Also, fix two small bugs, one which prevented overlay using the
'Available' status (change 'if $val' to 'if defined $val', since
'Available' is '0'), and another which prevented item overlay when
selecting the match record manually (as_imported was null in the DB).

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
Open-ILS/src/templates/vandelay/inc/queue.tt2
Open-ILS/src/templates/vandelay/inc/upload.tt2
Open-ILS/web/js/ui/default/vandelay/vandelay.js

index e7dbde7..5766231 100644 (file)
@@ -1015,6 +1015,7 @@ sub import_record_list_impl {
                     $logger->info("vl: $type direct overlay succeeded for queued rec ".
                         "$rec_id and overlay target $overlay_target");
                     $imported = 1;
+                    $rec->imported_as($overlay_target);
                 }
 
             } else {
@@ -1207,7 +1208,7 @@ sub import_record_list_impl {
     }
 
     # import the copies
-    import_record_asset_list_impl($conn, \@success_rec_ids, $requestor) if @success_rec_ids;
+    import_record_asset_list_impl($conn, \@success_rec_ids, $requestor, $args) if @success_rec_ids;
 
     $conn->respond({total => $$report_args{total}, progress => $$report_args{progress}});
     return undef;
@@ -1577,7 +1578,7 @@ sub retrieve_queue_summary {
 # Given a list of queued record IDs, imports all items attached to those records
 # --------------------------------------------------------------------------------
 sub import_record_asset_list_impl {
-    my($conn, $rec_ids, $requestor) = @_;
+    my($conn, $rec_ids, $requestor, $args) = @_;
 
     my $roe = new_editor(xact=> 1, requestor => $requestor);
 
@@ -1614,6 +1615,8 @@ sub import_record_asset_list_impl {
         # call number label for every copy per org per record.
         my $auto_callnumber = {};
 
+        my $opp_acq_copy_overlay = $args->{opp_acq_copy_overlay};
+        my @overlaid_copy_ids;
         for my $item_id (@$item_ids) {
             my $e = new_editor(requestor => $requestor, xact => 1);
             my $item = $e->retrieve_vandelay_import_item($item_id);
@@ -1673,6 +1676,38 @@ sub import_record_asset_list_impl {
                     respond_with_status($report_args);
                     next;
                 }
+            } elsif ($opp_acq_copy_overlay) { # we are going to "opportunistically" overlay received, in-process acq copies
+                # recv_time should never be null if the copy status is
+                # "In Process", so that is just a double-check
+                my $query = [
+                    {
+                        "recv_time" => {"!=" => undef},
+                        "owning_lib" => $item->owning_lib,
+                        "+acn" => {"record" => $rec->imported_as},
+                        "+acp" => {"status" => OILS_COPY_STATUS_IN_PROCESS}
+                    },
+                    {
+                        "join" => {
+                            "acp" => {
+                                "join" => "acn"
+                            }
+                        },
+                        "flesh" => 2,
+                        "flesh_fields" => {
+                            "acqlid" => ["eg_copy_id"],
+                            "acp" => ["call_number"]
+                        }
+                    }
+                ];
+                # don't overlay the same copy twice
+                $query->[0]{"+acp"}{"id"} = {"not in" => \@overlaid_copy_ids} if @overlaid_copy_ids;
+                if (my $acqlid = $e->search_acq_lineitem_detail($query)->[0]) {
+                    $copy = $acqlid->eg_copy_id;
+                    push(@overlaid_copy_ids, $copy->id);
+                }
+            }
+
+            if ($copy) { # we found a copy to overlay
 
                 # overlaying copies requires an extra permission
                 if (!$e->allowed("IMPORT_OVERLAY_COPY", $copy->call_number->owning_lib)) {
@@ -1743,7 +1778,7 @@ sub import_record_asset_list_impl {
                     price circ_as_type alert_message opac_visible circ_modifier/) {
 
                     my $val = $item->$_();
-                    $copy->$_($val) if $val and $val ne '';
+                    $copy->$_($val) if defined $val and $val ne '';
                 }
 
                 # de-flesh for update
index 0d8be97..d9118dc 100644 (file)
                         </select>
                     </td>
                 </tr>
+                <tr><td colspan='2' style='margin-top:10px;border-bottom:1px solid #888;border-top:2px solid #888'>
+                    <b>[% l('Copy Import Actions') %]</b>
+                </td></tr>
+                <tr>
+                    <td>[% l('Auto-overlay In-process Acquisition Copies') %]</td>
+                    <td colspan='4'><input jsId='vlUploadQueueAutoOverlayInprocessAcqCopies2' dojoType='dijit.form.CheckBox'/></td>
+                </tr>
 
                 <tr>
                     <td>
index bca673e..4db970d 100644 (file)
                 </select>
             </td>
         </tr>
+        <tr><td colspan='2' style='margin-top:10px;border-bottom:1px solid #888;border-top:2px solid #888'>
+            <b>[% l('Copy Import Actions') %]</b>
+        </td></tr>
+        <tr>
+            <td>[% l('Auto-overlay In-process Acquisitions Copies') %]</td>
+            <td colspan='4'><input jsId='vlUploadQueueAutoOverlayInprocessAcqCopies' dojoType='dijit.form.CheckBox'/></td>
+        </tr>
 
         <tr><td colspan='2' style='border-bottom:2px solid #888;'></td></tr>
         <tr><td colspan='2' style='padding-bottom: 10px;'></td></tr>
index 00f78e1..41b9a99 100644 (file)
@@ -1241,6 +1241,7 @@ function vlHandleQueueItemsAction(action) {
             vlUploadFtMergeProfile.attr('value',  vlUploadFtMergeProfile2.attr('value'));
             vlUploadQueueAutoOverlayBestMatch.attr('value',  vlUploadQueueAutoOverlayBestMatch2.attr('value'));
             vlUploadQueueAutoOverlayBestMatchRatio.attr('value',  vlUploadQueueAutoOverlayBestMatchRatio2.attr('value'));
+            vlUploadQueueAutoOverlayInprocessAcqCopies.attr('value',  vlUploadQueueAutoOverlayInprocessAcqCopies2.attr('value'));
 
             // attr('value') and various other incantations won't let me set 
             // the value on the checkedmultiselect, so we temporarily swap 
@@ -1271,6 +1272,8 @@ function vlHandleQueueItemsAction(action) {
             vlUploadQueueAutoOverlayBestMatch2.attr('value', false);
             vlUploadQueueAutoOverlayBestMatchRatio.attr('value', '0.0');
             vlUploadQueueAutoOverlayBestMatchRatio2.attr('value', '0.0');
+            vlUploadQueueAutoOverlayInprocessAcqCopies.attr('value', false);
+            vlUploadQueueAutoOverlayInprocessAcqCopies2.attr('value', false);
 
             // and... swap them back
             vlUploadTrashGroups2 = vlUploadTrashGroups;
@@ -1351,6 +1354,11 @@ function vlImportRecordQueue(type, queueId, recList, onload) {
         options.match_quality_ratio = vlUploadQueueAutoOverlayBestMatchRatio.attr('value');
     }
 
+    if(vlUploadQueueAutoOverlayInprocessAcqCopies.checked) {
+        options.opp_acq_copy_overlay = true; //"opp" for opportunistic
+        vlUploadQueueAutoOverlayInprocessAcqCopies.checked = false;
+    }
+
     var profile = vlUploadMergeProfile.attr('value');
     if(profile != null && profile != '') {
         options.merge_profile = profile;