LP#1619703 Transfer ACQ lineitem repairs WIP user/berick/lp1619703-transfer-lineitems
authorBill Erickson <berickxx@gmail.com>
Mon, 24 Jul 2017 21:51:26 +0000 (17:51 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 24 Jul 2017 21:51:31 +0000 (17:51 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index b76c719..fd0be66 100644 (file)
@@ -4342,60 +4342,58 @@ sub transfer_order_volume {
         where => {call_number => $cn_id}
     })->[0];
 
-    my $target_cn;
     my $evt;
 
+    # See if a matching CN already exists at the target bib
+    my $target_cn = OpenILS::Application::Cat::AssetCommon->volume_exists(
+        $e, $bib_id, $cn->label, $cn->owning_lib, $cn->prefix, $cn->suffix
+    );
+
     if ($copy_count->{count} == scalar(@$cn_copies)) {
-        # Order copies represent all copies linked to the callnumber
-        # See if a matching CN exists at the target bib and, if so,
-        # transfer our copies to the existing CN.  Otherwise,
-        # simply point our call number at the new bib.
-
-        # See if a matching CN already exists at the target bib
-        $target_cn = OpenILS::Application::Cat::AssetCommon->volume_exists(
-            $e, $bib_id, $cn->label, $cn->owning_lib, $cn->prefix, $cn->suffix
-        );
+        # Migrating all copies from the source call number to the
+        # target call number.
 
         if ($target_cn) {
-            # We are transferring all attached copies to the matching
-            # callnumber on the target bib.  This call number is no 
-            # longer needed.  Delete it.
-            $evt = OpenILS::Application::Cat::AssetCommon->delete_volume(
-                $e, $cn, 
-                1, # override
-                0, # delete copies
-                1  # skip copy checks
-            );
+            # Merge source call number into target call number to migrate
+            # all copies, transfer holds, and delete the source call number.
+            ($target_cn, $evt) = 
+                OpenILS::Application::Cat::AssetCommon->merge_volumes(
+                    $e, [$target_cn, $cn], $target_cn);
 
             return $evt if $evt;
 
         } else {
-            # No matching CN exists.  Point our CN at the target bib.
+            # No matching CN exists at the target bib.  Point our CN at 
+            # the target bib.  No need to transfer copies since the call 
+            # number object stays the same.
             $cn->record($bib_id);
             $cn->edit_date('now');
             $cn->editor($e->requestor->id);
             $e->update_asset_call_number($cn) or return $e->die_event;
             return undef; # all done
         }
-    }
 
-    # Copies need to be migrated to the target call number.
+    } else {
+        # Transferring only a subset of copies to the target call number.
 
-    ($target_cn, $evt) = 
-        OpenILS::Application::Cat::AssetCommon->find_or_create_volume(
-            $e, $cn->label, $bib_id, $cn->owning_lib, 
-            $cn->prefix, $cn->suffix, $cn->label_class
-        ) unless $target_cn;
+        if (!$target_cn) {
+            # Create a new target call number since none exists.
 
-    return $evt if $evt;
+            ($target_cn, $evt) = 
+                OpenILS::Application::Cat::AssetCommon->find_or_create_volume(
+                    $e, $cn->label, $bib_id, $cn->owning_lib, 
+                    $cn->prefix, $cn->suffix, $cn->label_class
+                );
+    
+            return $evt if $evt;
+        }
 
-    # ... transfer copies.
-    # Transfer order copies to the new call number.
-    for my $copy (@$cn_copies) {
-        $copy->call_number($target_cn->id);
-        $copy->edit_date('now');
-        $copy->editor($e->requestor->id);
-        $e->update_asset_copy($copy) or return $e->die_event;
+        for my $copy (@$cn_copies) {
+            $copy->call_number($target_cn->id);
+            $copy->edit_date('now');
+            $copy->editor($e->requestor->id);
+            $e->update_asset_copy($copy) or return $e->die_event;
+        }
     }
 
     return undef;