LP1975879 Propagate owning lib change to all copies user/berick/lp1975879-volcopy-edit-callnum-owner-v2
authorBill Erickson <berickxx@gmail.com>
Mon, 25 Jul 2022 15:37:59 +0000 (11:37 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 25 Jul 2022 16:36:18 +0000 (12:36 -0400)
When modifying the owning library of a call number from within the
Holdings tab of the item editor, propagate the modified owning lib value
to the circ_lib value of all attached items, regardless of whether the
user is currently editing a given item.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm

index 9baf350..0570354 100644 (file)
@@ -526,6 +526,7 @@ export class VolEditComponent implements OnInit {
 
         vol.owning_lib(orgId);
         vol.ischanged(true);
+        vol._propagate_owning_lib = true;
 
         // Move the vol node away from its previous org node and append
         // it to the children list of the target node.
@@ -550,18 +551,6 @@ export class VolEditComponent implements OnInit {
 
         targetOrgNode.children.push(volNode);
 
-        // If configured to do so, also update the circ_lib for any
-        // copies linked to this call number in this edit session.
-        if (this.volcopy.defaults.values.circ_lib_mod_with_owning_lib) {
-            volNode.children.forEach(copyNode => {
-                const copy = copyNode.target;
-                if (copy.circ_lib() !== orgId) {
-                    copy.circ_lib(orgId);
-                    copy.ischanged(true);
-                }
-            });
-        }
-
         this.emitSaveChange();
     }
 
index c650d6d..0a66730 100644 (file)
@@ -342,6 +342,10 @@ export class VolCopyComponent implements OnInit {
 
         this.context.volNodes().forEach(volNode => {
             const newVol = this.idl.clone(volNode.target);
+
+            // idl.clone() does not copy ephemeral fields
+            newVol._propagate_owning_lib = volNode.target._propagate_owning_lib;
+
             const copies: IdlObject[] = [];
 
             volNode.children.forEach(copyNode => {
@@ -472,7 +476,9 @@ export class VolCopyComponent implements OnInit {
             {   auto_merge_vols: true,
                 create_parts: true,
                 return_copy_ids: true,
-                force_delete_copies: true
+                force_delete_copies: true,
+                propagate_owning_lib:
+                    volumes.filter(v => v._propagate_owning_lib).map(v => v.id())
             }
 
         ).toPromise().then(copyIds => {
index deb7ad4..c48261b 100644 (file)
@@ -1202,18 +1202,53 @@ sub fleshed_volume_update {
     my $editor = new_editor( requestor => $reqr, xact => 1 );
     my $retarget_holds = [];
     my $auto_merge_vols = $options->{auto_merge_vols};
+
+    # List of call number IDs whose owning lib should be propagated
+    # to all of its pre-merge copies.
+    my $propagate_owning_lib = $options->{propagate_owning_lib} || [];
+
     my $create_parts = $options->{create_parts};
     my $copy_ids = [];
 
     for my $vol (@$volumes) {
-        $logger->info("vol-update: investigating volume ".$vol->id);
+        $logger->info("vol-update: investigating volume " . $vol->id);
+
 
         $vol->editor($reqr->id);
         $vol->edit_date('now');
 
-        my $copies = $vol->copies;
+        my $copies = $vol->copies || [];
         $vol->clear_copies;
 
+        if (grep {$_ == $vol->id} @$propagate_owning_lib) {
+            # When propagating owning lib changes to linked copies,
+            # it covers all copies, even those not included in the
+            # current edit session.  Grab others as needed and
+            # propagate to circ_lib as needed.
+
+            my $copy_ids = [map {$_->id} @$copies];
+
+            # Avoid in-empty-list
+            my @copy_filter = @$copy_ids ? (id => {'not in' => $copy_ids}) : ();
+
+            my $addl_copies = $editor->search_asset_copy(
+                {   call_number => $vol->id,
+                    @copy_filter,
+                    circ_lib => {'<>' => $vol->owning_lib},
+                    deleted => 'f'
+                }, {substream => 1} # could be many
+            );
+
+            $copies = [@$copies, @$addl_copies];
+
+            for (@$copies) {
+                if ($_->circ_lib != $vol->owning_lib) {
+                    $_->circ_lib($vol->owning_lib);
+                    $_->ischanged(1) unless ($_->isdeleted || $_->isnew);
+                }
+            }
+        }
+
         $vol->editor($editor->requestor->id);
         $vol->edit_date('now');