From 413aa8a33700b95319c7b911cf42aff40721c470 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. --- acqui/addorder.pl | 21 ++++++++++--------- acqui/neworderempty.pl | 15 +++++++------ .../prog/en/modules/acqui/neworderempty.tt | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 7297cbb4a0..f4636af129 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -371,17 +371,18 @@ if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { 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') { diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 2557a4c51b..34545be646 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -419,24 +419,27 @@ $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; 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; } 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, ); # fill template 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 7e2fa8d653..d74adb86a5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -49,6 +49,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' %]