From c079a23cfd1a6bab64c39dff1d2171515c3eb32c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 12 Mar 2025 16:25:37 +0000 Subject: [PATCH] Bug 39282: Ensure items are created using Item Information values if not using MarcItemFieldsToOrder When using MarcFieldsToOrder and not MarcItemFieldsToOrder it is expected that all of the item information will come from the second tab 'Item information' on addorderiso2709.pl Currently we are not and blank items are beign created To test: 1 - Apply unit tests 2 - prove -v t/db_dependent/Koha/MarcOrder.t 3 - It fails 4 - Set MarcItemFields to Order: price: 949$p quantity: 947$c budget_code: 947$f 5 - Ensure MarcItemFieldsToOrder is blank 6 - Find a basket in acquisitions 7 - Add to basket from a file 8 - Fill item information, set 'Matching' at top of form to 'Do not look for matchign records' and save 9 - Orders are added 10 - Click on a title 11 - Items do not load and an error is generated, this is because items don't have any values 12 - Check the DB: SELECT * FROM items WHERE homebranch IS NULL\G 13 - Note items from order are listed 14 - Apply the rest of the patches 15 - Repeat 6-10 16 - This time the items load successfully NOTE: This patch alone doesn't address all errors, but subsequent will, keeping separate to address each issue individually, but test plan can be executed as a whole against all Signed-off-by: John Vinke Signed-off-by: Martin Renvoize --- Koha/MarcOrder.pm | 4 +++- t/db_dependent/Koha/MarcOrder.t | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Koha/MarcOrder.pm b/Koha/MarcOrder.pm index edfe93d1b21..10379d9cf8d 100644 --- a/Koha/MarcOrder.pm +++ b/Koha/MarcOrder.pm @@ -958,7 +958,8 @@ sub create_items_and_generate_order_hash { my $itemcreation = 0; my @itemnumbers; - if ( C4::Context->preference('AcqCreateItem') ne 'cataloguing' ) { + # We directly create the items if MarcItemFieldsToOrder is populated (item fields have values) + if ( C4::Context->preference('AcqCreateItem') ne 'cataloguing' && @{ $fields->{homebranch} } ) { for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { $itemcreation = 1; my $item = Koha::Item->new( @@ -1052,6 +1053,7 @@ sub create_items_and_generate_order_hash { } } else { + # Here we are using the 'MARC' for items from the 'Item information' tab for creating the items # Add an orderline for each MARC record # Get quantity in the MARC record (1 if none) my $quantity = GetMarcQuantity( $fields->{marcrecord}, C4::Context->preference('marcflavour') ) || 1; diff --git a/t/db_dependent/Koha/MarcOrder.t b/t/db_dependent/Koha/MarcOrder.t index b3aac287ad6..41a0cadbab0 100755 --- a/t/db_dependent/Koha/MarcOrder.t +++ b/t/db_dependent/Koha/MarcOrder.t @@ -443,6 +443,7 @@ subtest 'add_items_from_import_record() - addorderiso2709.pl' => sub { subtest "Using MarcFieldsToOrder only" => sub { plan tests => 9; + t::lib::Mocks::mock_userenv( { branchcode => $branchcode } ); my $client_item_fields = { 'tags' => [ -- 2.48.1