From 38178eed4dfa3db4ac232bd1056edc1e1c836cf4 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 25 Jul 2022 11:37:59 -0400 Subject: [PATCH] LP1975879 Propagate owning lib change to all copies 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 --- .../app/staff/cat/volcopy/vol-edit.component.ts | 13 +------- .../src/app/staff/cat/volcopy/volcopy.component.ts | 8 ++++- .../src/perlmods/lib/OpenILS/Application/Cat.pm | 39 ++++++++++++++++++++-- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts index 9baf350890..057035482b 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts @@ -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(); } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts index c650d6d954..0a6673062a 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts @@ -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 => { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index deb7ad4036..c48261b080 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -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'); -- 2.11.0