LP#1269574 - make EDI also cancel acq-created copies user/csharp/lp1269574_delete_acq_copies_via_edi
authorChris Sharp <csharp@georgialibraries.org>
Wed, 8 Nov 2017 19:08:43 +0000 (14:08 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Wed, 8 Nov 2017 19:17:51 +0000 (14:17 -0500)
Before this change, acquisitions EDI did not attempt to
delete "real" copies attached to lineitem details. We
check for copies and delete them.

Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm

index 49feb96..ac59562 100644 (file)
@@ -17,6 +17,7 @@ use OpenILS::Utils::CStoreEditor q/new_editor/;
 use OpenILS::Utils::Fieldmapper;
 use OpenILS::Application::Acq::EDI::Translator;
 use OpenILS::Application::AppUtils;
+use OpenILS::Application::Cat::AssetCommon;
 my $U = 'OpenILS::Application::AppUtils';
 
 use OpenILS::Utils::EDIReader;
@@ -879,6 +880,22 @@ sub cancel_lids {
             }
         }
 
+        # we also need to delete any real copies attached
+        my $copy = $e->retrieve_asset_copy([
+            $lid->eg_copy_id,
+            {flesh => 1, flesh_fields => {acp => ['call_number']}}
+        ]);
+        if ($copy) {
+            $logger->info("EDI: deleting copy $copy->id and volume $copy->call_number for lid $lid->id");
+            my $evt = OpenILS::Application::Cat::AssetCommon->delete_copy($e, 1, $copy->call_number, $copy, 1, 1);
+            if ($evt) {
+                $e->rollback;
+                $logger->error("EDI: failed to delete copies for lid $lid->id: $evt");
+            }
+        } else {
+            $logger->debug("EDI: no copies or volumes to delete for lid $lid->id");
+        }
+
         $e->update_acq_lineitem_detail($lid);
         $cancel_count++;
     }