From 01e21f88fc3c5c6039784f48f7ece02dadbcbb05 Mon Sep 17 00:00:00 2001 From: blake Date: Mon, 13 Jun 2016 15:58:13 -0500 Subject: [PATCH] LP1411422 Copy details repeated in search results when item/volume moved with parts attached Added the code in perl to respect the existence of parts. Both "transferring volume" and "transferring items". "Transferring items" was coded to use open-ils.cat.asset.copy.fleshed.batch.update which means most of the work was done in js. The web based staff client is coded to use open-ils.cat.transfer_copies_to_volume. Decided to use that method for xul as well. Making it more consistent with the "transferring volume" code. Considered coding it to move the part level holds to the destination part but it's possible that the source part still has items. Signed-off-by: blake Signed-off-by: Jason Stephenson --- .../src/perlmods/lib/OpenILS/Application/Cat.pm | 101 ++++++++++++++++++++- .../staff_client/chrome/content/main/constants.js | 1 + Open-ILS/xul/staff_client/server/cat/util.js | 12 +-- 3 files changed, 100 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 19c0b6ad84..be3df96ba5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -850,10 +850,24 @@ sub transfer_copies_to_volume { # flesh and munge the copies my $fleshed_copies = []; - my ($copy, $copy_evt); + my $copy; foreach my $copy_id ( @{ $copies } ) { - ($copy, $copy_evt) = $U->fetch_copy($copy_id); - return $copy_evt if $copy_evt; + $copy = $editor->search_asset_copy([ + { id => $copy_id , deleted => 'f' }, + { + join => { + acpm => { + type => 'left', + join => { + bmp => { type => 'left' } + } + } + }, + flesh => 1, + flesh_fields => { acp => ['parts'] } + } + ])->[0]; + return OpenILS::Event->new('ASSET_COPY_NOT_FOUND') if !$copy; $copy->call_number( $volume ); $copy->circ_lib( $cn->owning_lib() ); $copy->ischanged( 't' ); @@ -871,6 +885,35 @@ sub transfer_copies_to_volume { return $evt; } + # take care of the parts + for my $copy (@$fleshed_copies) { + my $parts = $copy->parts; + next unless $parts; + my $part_objs = []; + foreach my $part (@$parts) { + my $part_label = $part->label; + my $part_obj = $editor->search_biblio_monograph_part( + { + label=>$part_label, + record=>$cn->record + } + )->[0]; + if (!$part_obj) { + $part_obj = Fieldmapper::biblio::monograph_part->new(); + $part_obj->label( $part_label ); + $part_obj->record( $cn->record ); + unless($editor->create_biblio_monograph_part($part_obj)) { + return $editor->die_event if $editor->die_event; + } + } + push @$part_objs, $part_obj; + } + $copy->parts( $part_objs ); + $copy->ischanged(1); + $evt = OpenILS::Application::Cat::AssetCommon->update_copy_parts($editor, $copy, 1); #delete_parts=1 + return $evt if $evt; + } + $editor->commit; $logger->info("copy to volume transfer successfully updated ".scalar(@$copies)." copies"); reset_hold_list($auth, $retarget_holds); @@ -1300,6 +1343,9 @@ sub batch_volume_transfer { } } + # record the difference between the destination bib and the present bib + my $same_bib = $vol->record == $rec; + # see if there is a volume at the destination lib that # already has the requested label my $existing_vol = $e->search_asset_call_number( @@ -1351,7 +1397,21 @@ sub batch_volume_transfer { # regardless of what volume was used as the destination, # update any copies that have moved over to the new lib - my $copies = $e->search_asset_copy({call_number=>$vol->id, deleted => 'f'}); + my $copies = $e->search_asset_copy([ + { call_number => $vol->id , deleted => 'f' }, + { + join => { + acpm => { + type => 'left', + join => { + bmp => { type => 'left' } + } + } + }, + flesh => 1, + flesh_fields => { acp => ['parts'] } + } + ]); # update circ lib on the copies - make this a method flag? for my $copy (@$copies) { @@ -1363,6 +1423,39 @@ sub batch_volume_transfer { $e->update_asset_copy($copy) or return $e->event; } + # update parts if volume is moving bib records + if( !$same_bib ) { + for my $copy (@$copies) { + my $parts = $copy->parts; + next unless $parts; + my $part_objs = []; + foreach my $part (@$parts) { + my $part_label = $part->label; + my $part_obj = $e->search_biblio_monograph_part( + { + label=>$part_label, + record=>$rec + } + )->[0]; + + if (!$part_obj) { + $part_obj = Fieldmapper::biblio::monograph_part->new(); + $part_obj->label( $part_label ); + $part_obj->record( $rec ); + unless($e->create_biblio_monograph_part($part_obj)) { + return $e->die_event if $e->die_event; + } + } + push @$part_objs, $part_obj; + } + + $copy->parts( $part_objs ); + $copy->ischanged(1); + $evt = OpenILS::Application::Cat::AssetCommon->update_copy_parts($e, $copy, 1); #delete_parts=1 + return $evt if $evt; + } + } + # Now see if any empty records need to be deleted after all of this for(@rec_ids) { diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index 8f2e313375..96e31fa2fc 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -107,6 +107,7 @@ var api = { 'FM_ACP_UNFLESHED_BATCH_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.batch.retrieve', 'secure' : false }, 'FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed.batch.retrieve.authoritative', 'secure' : false }, 'FM_ACP_FLESHED_BATCH_UPDATE' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.asset.copy.fleshed.batch.update' }, + 'FM_ACP_TRANSFER_COPIES_BATCH' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.transfer_copies_to_volume' }, 'FM_ACP_COUNT' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.biblio.record.copy_count.staff', 'secure' : false }, 'FM_ACP_COUNT.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.biblio.record.copy_count.staff.authoritative', 'secure' : false }, 'FM_ACPL_RETRIEVE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.copy_location.retrieve.all', 'secure' : false }, diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js index f7da88609c..2f4e93aac1 100644 --- a/Open-ILS/xul/staff_client/server/cat/util.js +++ b/Open-ILS/xul/staff_client/server/cat/util.js @@ -184,17 +184,9 @@ cat.util.transfer_copies = function(params) { JSAN.use('util.functional'); - var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ params.copy_ids ]); - - for (var i = 0; i < copies.length; i++) { - copies[i].call_number( data.marked_volume ); - copies[i].circ_lib( params.owning_lib ); - copies[i].ischanged( 1 ); - } - var robj = network.simple_request( - 'FM_ACP_FLESHED_BATCH_UPDATE', - [ ses(), copies, true ], + 'FM_ACP_TRANSFER_COPIES_BATCH', + [ ses(), data.marked_volume , params.copy_ids ], null, { 'title' : $("catStrings").getString('staff.cat.util.transfer_copies.override_transfer_failure'), -- 2.11.0