Bugzilla – Attachment 33237 Details for
Bug 12743
Allow default values from the ACQ framework to be used when creating a record in acquisitions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 12743: ACQ: default values for catalogue records
SIGNED-OFF-Bug-12743-ACQ-default-values-for-catalo.patch (text/plain), 6.57 KB, created by
Gaetan Boisson
on 2014-11-05 09:10:31 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 12743: ACQ: default values for catalogue records
Filename:
MIME Type:
Creator:
Gaetan Boisson
Created:
2014-11-05 09:10:31 UTC
Size:
6.57 KB
patch
obsolete
>From da8e4f8c858bc689a0e5fce478e3a8447a12bfd9 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 20 Aug 2014 17:05:19 +0200 >Subject: [PATCH] [SIGNED-OFF] Bug 12743: ACQ: default values for catalogue > records > >At the moment, it is possible to create records in acquisitions, but the >ACQ framework is only used for items created in this module. > >This patch allows to defined default values in the ACQ framework for >records created on the acquisition module. > >Test plan: >1/ Make sure you have the ACQ framework created (otherwise create it >from the default framework). >2/ Define a default value for a field (for instance 099$z=1). >3/ Go in the acquisition module and create a new order from a new >record. >4/ Fill mandatory information and save. >5/ Go on the detail page of this record and verify the default value >exist. > >Signed-off-by: Gaetan Boisson <gaetan.boisson@biblibre.com> >--- > C4/Acquisition.pm | 53 ++++++++++++++- > acqui/addorder.pl | 2 + > t/db_dependent/Acquisition/FillWithDefaultValues.t | 79 ++++++++++++++++++++++ > 3 files changed, 133 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Acquisition/FillWithDefaultValues.t > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index f9e8c49..6618b19 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -23,7 +23,6 @@ use Carp; > use C4::Context; > use C4::Debug; > use C4::Dates qw(format_date format_date_in_iso); >-use MARC::Record; > use C4::Suggestions; > use C4::Biblio; > use C4::Contract; >@@ -33,6 +32,11 @@ use C4::Templates qw(gettemplate); > use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Acquisition::Order; > >+use C4::Koha qw( subfield_is_koha_internal_p ); >+ >+use MARC::Field; >+use MARC::Record; >+ > use Time::localtime; > use HTML::Entities; > >@@ -81,6 +85,8 @@ BEGIN { > > &AddClaim > &GetBiblioCountByBasketno >+ >+ &FillWithDefaultValues > ); > } > >@@ -2896,6 +2902,51 @@ sub GetBiblioCountByBasketno { > return $sth->fetchrow; > } > >+=head3 FillWithDefaultValues >+ >+FillWithDefaultValues( $marc_record ); >+ >+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. >+ >+=cut >+ >+sub FillWithDefaultValues { >+ my ($record) = @_; >+ my $tagslib = C4::Biblio::GetMarcStructure( 1, 'ACQ' ); >+ 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 ( subfield_is_koha_internal_p($subfield) ); >+ my $defaultvalue = $tagslib->{$tag}{$subfield}{defaultvalue}; >+ if ( defined $defaultvalue and $defaultvalue ne '' ) { >+ my @fields = $record->field($tag); >+ if (@fields) { >+ for my $field (@fields) { >+ unless ( defined $field->subfield($subfield) ) { >+ $field->add_subfields( >+ $subfield => $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 a8e71a5..88482e5 100755 >--- a/acqui/addorder.pl >+++ b/acqui/addorder.pl >@@ -257,6 +257,8 @@ if ( $orderinfo->{quantity} ne '0' ) { > "aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "", > }); > >+ C4::Acquisition::FillWithDefaultValues( $record ); >+ > # create the record in catalogue, with framework '' > my ($biblionumber,$bibitemnum) = AddBiblio($record,''); > # change suggestion status if applicable >diff --git a/t/db_dependent/Acquisition/FillWithDefaultValues.t b/t/db_dependent/Acquisition/FillWithDefaultValues.t >new file mode 100755 >index 0000000..758fa69 >--- /dev/null >+++ b/t/db_dependent/Acquisition/FillWithDefaultValues.t >@@ -0,0 +1,79 @@ >+use Modern::Perl; >+use Test::More tests => 5; >+use Test::MockModule; >+ >+use MARC::Record; >+use MARC::Field; >+ >+use C4::Context; >+use C4::Acquisition qw( FillWithDefaultValues ); >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+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 value for an existing field >+ '245' => { >+ c => { defaultvalue => $default_author }, >+ }, >+ >+ # default for a nonexisting field >+ '099' => { >+ x => { defaultvalue => $default_x }, >+ }, >+ }; >+ } >+); >+ >+my $record = MARC::Record->new; >+$record->leader('03174nam a2200445 a 4500'); >+my @fields = ( >+ 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' >+); >-- >1.9.1
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 12743
:
31028
|
31090
|
31098
|
33196
|
33237
|
34894
|
39032