From 12531ace910420ed7d8c953b1282a94204672d0a Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 19 Dec 2019 14:17:39 +0000 Subject: [PATCH] Bug 24276: Add FillWithDefaultValues call in neworderempty Apply mandatory defaults from the ACQ framework to records from external source in Acquisition. Test plan: [1] Add 'BK' as mandatory default in ACQ framework for 942$c. [2] Add order to basket via external source. [3] Check 942$c on detail page of new record, MARC tab. Signed-off-by: Bernardo Gonzalez Kriegel First added 942 field and subfields to ACQ fw, then followed test plan. wo/patch 942 is not added, w/patch it is. Work as described. --- C4/Acquisition.pm | 9 +++++++-- acqui/neworderempty.pl | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index ffca1ffd4d..e26249eccb 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -3258,16 +3258,20 @@ sub NotifyOrderUsers { =head3 FillWithDefaultValues -FillWithDefaultValues( $marc_record ); +FillWithDefaultValues( $marc_record, $params ); This will update the record with default value defined in the ACQ framework. For all existing fields, if a default value exists and there are no subfield, it will be created. If the field does not exist, it will be created too. +If the parameter only_mandatory => 1 is passed via $params, only the mandatory +defaults are being applied to the record. + =cut sub FillWithDefaultValues { - my ($record) = @_; + my ( $record, $params ) = @_; + my $mandatory = $params->{only_mandatory}; my $tagslib = C4::Biblio::GetMarcStructure( 1, 'ACQ', { unsafe => 1 } ); if ($tagslib) { my ($itemfield) = @@ -3277,6 +3281,7 @@ sub FillWithDefaultValues { next if $tag == $itemfield; for my $subfield ( sort keys %{ $tagslib->{$tag} } ) { next if IsMarcStructureInternal($tagslib->{$tag}{$subfield}); + next if $mandatory && !$tagslib->{$tag}{$subfield}{mandatory}; my $defaultvalue = $tagslib->{$tag}{$subfield}{defaultvalue}; if ( defined $defaultvalue and $defaultvalue ne '' ) { my @fields = $record->field($tag); diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index f25ae6a8bf..7518a7d3ef 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -163,6 +163,7 @@ if ( $ordernumber eq '' and defined $params->{'breedingid'}){ exit; } #from this point: add a new record + C4::Acquisition::FillWithDefaultValues($marcrecord, {only_mandatory => 1}); my $bibitemnum; $params->{'frameworkcode'} or $params->{'frameworkcode'} = ""; ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $params->{'frameworkcode'} ); -- 2.17.1