From: Mike Rylander Date: Tue, 1 Sep 2015 19:16:31 +0000 (-0400) Subject: webstaff: Allow automatic part creation X-Git-Tag: sprint4-merge-nov22~1008 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4805efa9b793a0ac7021071a95815bda15d758c7;p=working%2FEvergreen.git webstaff: Allow automatic part creation Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 3193219c29..4a5d1b3957 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -721,7 +721,7 @@ __PACKAGE__->register_method( sub fleshed_copy_update { - my( $self, $conn, $auth, $copies, $delete_stats, $oargs ) = @_; + my( $self, $conn, $auth, $copies, $delete_stats, $oargs, $create_parts ) = @_; return 1 unless ref $copies; my( $reqr, $evt ) = $U->checkses($auth); return $evt if $evt; @@ -733,7 +733,7 @@ sub fleshed_copy_update { } my $retarget_holds = []; $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies( - $editor, $oargs, undef, $copies, $delete_stats, $retarget_holds, undef); + $editor, $oargs, undef, $copies, $delete_stats, $retarget_holds, undef, $create_parts); if( $evt ) { $logger->info("fleshed copy update failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt)); @@ -865,6 +865,7 @@ sub fleshed_volume_update { my $editor = new_editor( requestor => $reqr, xact => 1 ); my $retarget_holds = []; my $auto_merge_vols = $options->{auto_merge_vols}; + my $create_parts = $options->{create_parts}; for my $vol (@$volumes) { $logger->info("vol-update: investigating volume ".$vol->id); @@ -908,7 +909,7 @@ sub fleshed_volume_update { if( $copies and @$copies and !$vol->isdeleted ) { $_->call_number($vol->id) for @$copies; $evt = $assetcom->update_fleshed_copies( - $editor, $oargs, $vol, $copies, $delete_stats, $retarget_holds, undef); + $editor, $oargs, $vol, $copies, $delete_stats, $retarget_holds, undef, $create_parts); return $evt if $evt; } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm index 4d78cb5c6f..1f6075fbe8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm @@ -160,7 +160,7 @@ sub update_copy_stat_entries { # authoritative list for the copy. existing part maps not targeting # these parts will be deleted from the DB sub update_copy_parts { - my($class, $editor, $copy, $delete_maps) = @_; + my($class, $editor, $copy, $delete_maps, $create_parts) = @_; return undef if $copy->isdeleted; return undef unless $copy->ischanged or $copy->isnew; @@ -197,6 +197,15 @@ sub update_copy_parts { # if this link already exists in the DB, don't attempt to re-create it next if( grep{$_->part == $incoming_part->id} @$maps ); + + if ($incoming_part->isnew) { + next unless $create_parts; + my $new_part = Fieldmapper::biblio::monograph_part->new(); + $new_part->record( $incoming_part->record ); + $new_part->label( $incoming_part->label ); + $incoming_part = $editor->create_biblio_monograph_part($new_part) + or return $editor->event; + } my $new_map = Fieldmapper::asset::copy_part_map->new(); @@ -284,7 +293,7 @@ sub check_hold_retarget { # this does the actual work sub update_fleshed_copies { - my($class, $editor, $override, $vol, $copies, $delete_stats, $retarget_holds, $force_delete_empty_bib) = @_; + my($class, $editor, $override, $vol, $copies, $delete_stats, $retarget_holds, $force_delete_empty_bib, $create_parts) = @_; $override = { all => 1 } if($override && !ref $override); $override = { all => 0 } if(!ref $override); @@ -340,7 +349,7 @@ sub update_fleshed_copies { $evt = $class->update_copy_stat_entries($editor, $copy, $delete_stats); $copy->parts( $parts ); # probably okay to use $delete_stats here for simplicity - $evt = $class->update_copy_parts($editor, $copy, $delete_stats); + $evt = $class->update_copy_parts($editor, $copy, $delete_stats, $create_parts); return $evt if $evt; }