From 2e1cf1d040293c28ce40ac2c83672190c97806f8 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 16 Oct 2023 12:36:06 +0000 Subject: [PATCH] Bug 35044: Update: Acquisition orders Test plan, k-t-d: Preparation: Create additional fields for table 'aqorders': 2 text fields, one repeatable, one not-repeatable 2 AV fields, one repeatable, one not-repeatable 2 MARC fields, one 'get' and one 'set', both non-repeatable, MARC field 942$c Attempt to create a repeatable MARC field (get or set). Notice you're unable to. 1) Add a new order for an existing basket, with an existing record, visit: /cgi-bin/koha/acqui/neworderempty.pl?booksellerid=1&basketno=1&biblionumber=76 2) Set the mandatory "Koha item type" for the item. Click the 'Add item' button below. 3) Notice the accounting details now have quantity:1 4) Set the mandatory "Fund" input in accounting details. 5) At the bottom, fill in all additional fields, click the '+New' and 'Clear' links, hit 'Save' 6) In the orders table shown, click "Modify". Notice all the fields are presented correctly in the edit form. Signed-off-by: Martin Renvoize --- acqui/addorder.pl | 35 ++++++++++--------- acqui/neworderempty.pl | 15 ++++---- .../prog/en/modules/acqui/neworderempty.tt | 1 + 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 2fc99b66ebe..45bfa93b406 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -117,17 +117,17 @@ if it is an order from an existing suggestion : the id of this suggestion. =cut use Modern::Perl; -use CGI qw ( -utf8 ); +use CGI qw ( -utf8 ); use JSON qw ( to_json encode_json ); use C4::Acquisition qw( FillWithDefaultValues ModOrderUsers ); -use C4::Auth qw( get_template_and_user ); +use C4::Auth qw( get_template_and_user ); use C4::Barcodes; -use C4::Biblio qw( AddBiblio GetMarcFromKohaField TransformHtmlToXml TransformKohaToMarc ); -use C4::Budgets qw( GetBudget GetBudgetSpent GetBudgetOrdered FieldsForCalculatingFundValues ); -use C4::Items qw( AddItemFromMarc ); -use C4::Log qw( logaction ); -use C4::Output qw( output_html_with_http_headers ); +use C4::Biblio qw( AddBiblio GetMarcFromKohaField TransformHtmlToXml TransformKohaToMarc ); +use C4::Budgets qw( GetBudget GetBudgetSpent GetBudgetOrdered FieldsForCalculatingFundValues ); +use C4::Items qw( AddItemFromMarc ); +use C4::Log qw( logaction ); +use C4::Output qw( output_html_with_http_headers ); use C4::Suggestions qw( ModSuggestion ); use Koha::Acquisition::Baskets; use Koha::Acquisition::Currencies qw( get_active ); @@ -387,17 +387,19 @@ if ( $op eq 'cud-order' ) { ModOrderUsers( $order->ordernumber, @order_users ); # Retrieve and save additional fields values - my @additional_fields = Koha::AdditionalFields->search( { tablename => 'aqorders' } )->as_list; - my @additional_field_values; - foreach my $af (@additional_fields) { - my $id = $af->id; - my $value = $input->param("additional_field_$id"); - push @additional_field_values, { - id => $id, - value => $value, + my @additional_fields; + my $order_fields = Koha::AdditionalFields->search( { tablename => 'aqorders' } ); + while ( my $field = $order_fields->next ) { + my @field_values = $input->param( 'additional_field_' . $field->id ); + foreach my $value (@field_values){ + push @additional_fields, + { + id => $field->id, + value => $value, + } if $value; }; } - $order->set_additional_fields( \@additional_field_values ); + $order->set_additional_fields( \@additional_fields ); # now, add items if applicable if ( $basket->effective_create_items eq 'ordering' ) { @@ -482,4 +484,3 @@ if ( $op eq 'cud-order' ) { print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); exit; } - diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 1ec08269f6a..69c703dc4f1 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -420,26 +420,29 @@ $quantity //= 0; # Get additional fields my $record; my @additional_fields = Koha::AdditionalFields->search({ tablename => 'aqorders' })->as_list; -my %additional_field_values; +my $additional_field_values; my $items; if ($ordernumber) { my $order = Koha::Acquisition::Orders->find($ordernumber); - foreach my $value ($order->additional_field_values->as_list) { - $additional_field_values{$value->field_id} = $value->value; - } + $additional_field_values = $order->get_additional_field_values_for_template; $items = $order->items; } elsif ( $biblionumber ) { + my %additional_field_values; foreach my $af (@additional_fields) { + my @marc_field_values; if ($af->marcfield) { $record //= Koha::Biblios->find($biblionumber)->metadata->record; my ($field, $subfield) = split /\$/, $af->marcfield; - $additional_field_values{$af->id} = $record->subfield($field, $subfield); + push @marc_field_values, $record->subfield( $field, $subfield ) if $record->subfield( $field, $subfield ); + $additional_field_values{ $af->id } = \@marc_field_values; } } + $additional_field_values = \%additional_field_values } + $template->param( additional_fields => \@additional_fields, - additional_field_values => \%additional_field_values, + additional_field_values => $additional_field_values, items => $items, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index e9b62396f14..011c49b65c1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -51,6 +51,7 @@ [% Asset.js("js/acq.js") | $raw %] [% Asset.js("js/additem.js") | $raw %] [% Asset.js("js/cataloging.js") | $raw %] + [% Asset.js("js/additional-fields-entry.js") | $raw %] [% INCLUDE 'calendar.inc' %] [% INCLUDE 'select2.inc' %]