From cba15aaa093f80602177d18e9693b53742ddf74f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 22 Jun 2023 16:06:11 -0300 Subject: [PATCH] Bug 34022: Adjust items data structure When creating items at receiving, the generated data structure didn't match what the code expected, so this patch adapts the code to match the new data structure introduced by bug 8179. Once I fixed that, I noticed that the $.ajax request payload, when it contains an array parameter, it renames it like `param[]`. So the finishreceive.pl controller is adjusted to this behaviour for the 'on receiving' use case. To test: 1. Apply this patch 2. Create a basket with 'create items on receive' 3. Create an order line 4. Close basket 5. Receive shipment 6. Enter invoice number 7. Click on Receive link in the table 8. Fill out item form, make sure all mandatory fields are set 9. Save 10. Verify that the order line is marked as 'received' 11. Verify that there item is created on the record => SUCCESS: Works as expected 12. Sign off :-D Signed-off-by: Michaela Sieber Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit a40c512bf083a1bb48daeecd2f407b4f5586d819) Signed-off-by: Fridolin Somers --- acqui/finishreceive.pl | 10 +++++----- .../prog/en/modules/acqui/orderreceive.tt | 14 ++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index b682724139..a9803b8542 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -145,11 +145,11 @@ if ($quantityrec > $origquantityrec ) { # now, add items if applicable if ($basket->effective_create_items eq 'receiving') { - my @tags = $input->multi_param('tag'); - my @subfields = $input->multi_param('subfield'); - my @field_values = $input->multi_param('field_value'); - my @serials = $input->multi_param('serial'); - my @itemid = $input->multi_param('itemid'); + my @tags = $input->multi_param('tag[]'); + my @subfields = $input->multi_param('subfield[]'); + my @field_values = $input->multi_param('field_value[]'); + my @serials = $input->multi_param('serial[]'); + my @itemid = $input->multi_param('itemid[]'); #Rebuilding ALL the data for items into a hash # parting them on $itemid. my %itemhash; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index 749e68dc70..6a0091244e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -695,14 +695,12 @@ params['replacementprice'] = row.replacement_price; params['unitprice'] = ( invoiceincgst=="1" ) ? ( row.unit_price_tax_included || row.ecost_tax_included ) : ( row.unit_price_tax_excluded || row.ecost_tax_excluded ); params['order_internalnote'] = row.internal_note; - if(effective_create_items == 'receiving') { - Object.keys(row.items).forEach(function(key) { - var item = row.items[key]; - Object.keys(item).forEach(function(key) { - var field = item[key]; - Object.keys(field).forEach(function(key) { - if(!params[key]) params[key] = []; - params[key].push(item[key]); + if (effective_create_items == 'receiving') { + row.items.forEach(function(item){ + Object.keys(item).forEach(function(item_field){ + Object.keys(item[item_field]).forEach(function(key){ + if (!params[key]) params[key] = []; + params[key].push(item[item_field][key]); }); }); }); -- 2.39.5