Bugzilla – Attachment 194194 Details for
Bug 41763
Use Koha::Biblioframework->fill_with_default_values instead of C4::Acquisition::FillWithDefaultValue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41763: Use fill_default_value instead of FillWithDefaultValues
Bug-41763-Use-filldefaultvalue-instead-of-FillWith.patch (text/plain), 10.09 KB, created by
David Nind
on 2026-02-28 08:57:43 UTC
(
hide
)
Description:
Bug 41763: Use fill_default_value instead of FillWithDefaultValues
Filename:
MIME Type:
Creator:
David Nind
Created:
2026-02-28 08:57:43 UTC
Size:
10.09 KB
patch
obsolete
>From 17a6068840e11863fb0b7938eeb7aec4150ab327 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= <johanna.raisa@gmail.com> >Date: Fri, 6 Feb 2026 11:03:32 +0200 >Subject: [PATCH] Bug 41763: Use fill_default_value instead of > FillWithDefaultValues > >This patch adds unified version of the code to fill default values >in acquisition order creation. > >It uses the fill_default_value method from the Koha::Biblioframeworks >instead of the C4::Acquisition::FillWithDefaultValues module. > >Test plan: >1. Create or modify acquisition framework ACQ with a default value > for a field (for instance 099$z=1). >2. Create a new acquisition order from a new record. >3. Verify the default value exist in the order detail page. > >Sponsored-by: Koha-Suomi Oy >Signed-off-by: David Nind <david@davidnind.com> >--- > C4/Acquisition.pm | 52 -------- > acqui/addorder.pl | 8 +- > acqui/neworderempty.pl | 7 +- > .../Acquisition/FillWithDefaultValues.t | 122 ------------------ > 4 files changed, 11 insertions(+), 178 deletions(-) > delete mode 100755 t/db_dependent/Acquisition/FillWithDefaultValues.t > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index be67162a9c..b885966611 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -59,8 +59,6 @@ BEGIN { > ModOrderUsers > NotifyOrderUsers > >- FillWithDefaultValues >- > get_rounded_price > get_rounding_sql > ); >@@ -2957,56 +2955,6 @@ sub NotifyOrderUsers { > } > } > >-=head3 FillWithDefaultValues >- >-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, $params ) = @_; >- my $mandatory = $params->{only_mandatory}; >- my $tagslib = C4::Biblio::GetMarcStructure( 1, 'ACQ', { unsafe => 1 } ); >- if ($tagslib) { >- my ($itemfield) = C4::Biblio::GetMarcFromKohaField('items.itemnumber'); >- for my $tag ( sort keys %$tagslib ) { >- next unless $tag; >- 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); >- if (@fields) { >- for my $field (@fields) { >- if ( $field->is_control_field ) { >- $field->update($defaultvalue) if not defined $field->data; >- } elsif ( not defined $field->subfield($subfield) ) { >- $field->add_subfields( $subfield => $defaultvalue ); >- } >- } >- } else { >- if ( $tag < 10 ) { # is_control_field >- $record->insert_fields_ordered( MARC::Field->new( $tag, $defaultvalue ) ); >- } else { >- $record->insert_fields_ordered( >- MARC::Field->new( $tag, '', '', $subfield => $defaultvalue ) ); >- } >- } >- } >- } >- } >- } >-} >- > 1; > __END__ > >diff --git a/acqui/addorder.pl b/acqui/addorder.pl >index 42309ea2ce..af3da95362 100755 >--- a/acqui/addorder.pl >+++ b/acqui/addorder.pl >@@ -120,7 +120,7 @@ use Modern::Perl; > use CGI qw ( -utf8 ); > use JSON qw ( to_json encode_json ); > >-use C4::Acquisition qw( FillWithDefaultValues ModOrderUsers ); >+use C4::Acquisition qw( ModOrderUsers ); > use C4::Auth qw( get_template_and_user ); > use C4::Barcodes; > use C4::Biblio qw( AddBiblio GetMarcFromKohaField TransformHtmlToXml TransformKohaToMarc ); >@@ -134,6 +134,7 @@ use Koha::Acquisition::Baskets; > use Koha::Acquisition::Currencies; > use Koha::Acquisition::Orders; > use Koha::AdditionalFields; >+use Koha::BiblioFrameworks; > use Koha::DateUtils qw( dt_from_string ); > > ### "-------------------- addorder.pl ----------" >@@ -329,7 +330,10 @@ if ( $op eq 'cud-order' ) { > } > ); > } >- C4::Acquisition::FillWithDefaultValues($record); >+ my $framework = Koha::BiblioFrameworks->find('ACQ'); >+ if ($framework) { >+ $framework->fill_with_default_values($record); >+ } > > if ( !$confirm_not_duplicate ) { > my ( $dupe_biblionumber, $dupe_title ) = FindDuplicate($record); >diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl >index 307c48509e..f874e7318b 100755 >--- a/acqui/neworderempty.pl >+++ b/acqui/neworderempty.pl >@@ -70,7 +70,7 @@ use C4::Context; > use C4::Auth qw( get_template_and_user ); > use C4::Budgets qw( GetBudget GetBudgetHierarchy CanUserUseBudget ); > >-use C4::Acquisition qw( GetOrder GetBasket FillWithDefaultValues GetOrderUsers ); >+use C4::Acquisition qw( GetOrder GetBasket GetOrderUsers ); > use C4::Contract qw( GetContract ); > use C4::Suggestions qw( GetSuggestionInfo ); > use C4::Biblio qw( >@@ -185,7 +185,10 @@ if ( $ordernumber eq '' and defined $breedingid ) { > } > > #from this point: add a new record >- C4::Acquisition::FillWithDefaultValues( $marcrecord, { only_mandatory => 1 } ); >+ my $framework = Koha::BiblioFrameworks->find('ACQ'); >+ if ($framework) { >+ $framework->fill_with_default_values( $marcrecord, { only_mandatory => 1 } ); >+ } > my $bibitemnum; > ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $frameworkcode ); > >diff --git a/t/db_dependent/Acquisition/FillWithDefaultValues.t b/t/db_dependent/Acquisition/FillWithDefaultValues.t >deleted file mode 100755 >index ea735e48dc..0000000000 >--- a/t/db_dependent/Acquisition/FillWithDefaultValues.t >+++ /dev/null >@@ -1,122 +0,0 @@ >-use Modern::Perl; >-use Test::NoWarnings; >-use Test::More tests => 13; >-use Test::MockModule; >- >-use MARC::Record; >-use MARC::Field; >- >-use C4::Context; >-use C4::Acquisition qw( FillWithDefaultValues ); >-use Koha::Database; >- >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >- >-my $biblio_module = Test::MockModule->new('C4::Biblio'); >-my $default_author = 'default author'; >-my $default_x = 'my default value'; >-$biblio_module->mock( >- 'GetMarcStructure', >- sub { >- { >- # default for a control field >- '008' => { >- x => { defaultvalue => $default_x }, >- }, >- >- # default value for an existing field >- '245' => { >- c => { defaultvalue => $default_author, mandatory => 1 }, >- mandatory => 0, >- repeatable => 0, >- tab => 0, >- lib => 'a lib', >- }, >- >- # default for a nonexisting field >- '099' => { >- x => { defaultvalue => $default_x }, >- }, >- '942' => { >- c => { defaultvalue => 'BK', mandatory => 1 }, >- d => { defaultvalue => '942d_val' }, >- f => { defaultvalue => '942f_val' }, >- }, >- }; >- } >-); >- >-my $record = MARC::Record->new; >-$record->leader('03174nam a2200445 a 4500'); >-my @fields = ( >- MARC::Field->new( >- '008', '1', ' ', >- '@' => '120829t20132012nyu bk 001 0ceng', >- ), >- MARC::Field->new( >- 100, '1', ' ', >- a => 'Knuth, Donald Ervin', >- d => '1938', >- ), >- MARC::Field->new( >- 245, '1', '4', >- a => 'The art of computer programming', >- c => 'Donald E. Knuth.', >- ), >- MARC::Field->new( >- 245, '1', '4', a => 'my second title', >- ), >-); >- >-$record->append_fields(@fields); >- >-C4::Acquisition::FillWithDefaultValues($record); >- >-my @fields_245 = $record->field(245); >-is( scalar(@fields_245), 2, 'No new 245 field has been created' ); >-my @subfields_245_0 = $fields_245[0]->subfields; >-my @subfields_245_1 = $fields_245[1]->subfields; >-is_deeply( >- \@subfields_245_0, >- [ [ 'a', 'The art of computer programming' ], [ 'c', 'Donald E. Knuth.' ] ], >- 'first 245 field has not been updated' >-); >-is_deeply( >- \@subfields_245_1, >- [ [ 'a', 'my second title' ], [ 'c', $default_author ] ], >- 'second 245 field has a new subfield c with a default value' >-); >- >-my @fields_099 = $record->field('099'); >-is( scalar(@fields_099), 1, '1 new 099 field has been created' ); >-my @subfields_099 = $fields_099[0]->subfields; >-is_deeply( >- \@subfields_099, >- [ [ 'x', $default_x ] ], >- '099$x contains the default value' >-); >- >-# Test controlfield default >-$record->field('008')->update(undef); >-C4::Acquisition::FillWithDefaultValues($record); >-is( $record->field('008')->data, $default_x, 'Controlfield got default' ); >- >-is( $record->subfield( '942', 'd' ), '942d_val', 'Check 942d' ); >- >-# Now test only_mandatory parameter >-$record->delete_fields( $record->field('245') ); >-$record->delete_fields( $record->field('942') ); >-$record->append_fields( MARC::Field->new( '942', '', '', 'f' => 'f val' ) ); >- >-# We deleted 245 and replaced 942. If we only apply mandatories, we should get >-# back 245c again and 942c but not 942d. 942f should be left alone. >-C4::Acquisition::FillWithDefaultValues( $record, { only_mandatory => 1 } ); >-@fields_245 = $record->field(245); >-is( scalar @fields_245, 1, 'Only one 245 expected' ); >-is( $record->subfield( '245', 'c' ), $default_author, '245c restored' ); >-is( $record->subfield( '942', 'c' ), 'BK', '942c also restored' ); >-is( $record->subfield( '942', 'd' ), undef, '942d should not be there' ); >-is( $record->subfield( '942', 'f' ), 'f val', '942f untouched' ); >- >-$schema->storage->txn_rollback; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41763
:
192588
|
194193
| 194194