From 55e5c82ab593c180e0b73f1cd13bbc71ee7a39c6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Sep 2014 20:25:27 +0200 Subject: [PATCH] Bug 12891: NewOrder does not return ordernumber if ordernumber is defined The behavior is quite weird, but $schema->resultset('Table')->create($data)->id does not return the id inserted if $data contains the key. To be more clear, in this case $schema->resultset('Aqorder')->create($new_order)->id returns an empty string because $new_order->{ordernumber} is an empty string! This was not caught by the unit tests, I added one. Test plan: - AcqCreateItem set to ordering - Create an order with items and verify items are correctly linked to the order. Signed-off-by: Dobrica Pavlinusic Signed-off-by: Katrin Fischer Confirmed that without the patch the created item is not linked to the order (entry in aqorders_items). With the patch, it works as expected. Passes tests and Koha QA script. Signed-off-by: Tomas Cohen Arazi --- C4/Acquisition.pm | 3 +++ t/db_dependent/Acquisition.t | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index d55eda9e36..0dac85ff62 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1266,6 +1266,8 @@ sub NewOrder { my $dbh = C4::Context->dbh; my @params; + croak "The ordernumber parameter should not be provided on calling NewOrder" + if $orderinfo->{ordernumber}; # if these parameters are missing, we can't continue for my $key (qw/basketno quantity biblionumber budget_id/) { @@ -1281,6 +1283,7 @@ sub NewOrder { my $schema = Koha::Database->new()->schema; my $columns = ' '.join(' ', $schema->source('Aqorder')->columns).' '; my $new_order = { map { $columns =~ / $_ / ? ($_ => $orderinfo->{$_}) : () } keys(%$orderinfo) }; + $new_order->{ordernumber} ||= undef; my $rs = $schema->resultset('Aqorder'); my $ordernumber = $rs->create($new_order)->id; diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 837024a297..0ae9ab7265 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -195,7 +195,8 @@ my @order_content = ( budget_id => $budget->{budget_id}, uncertainprice => 0, order_internalnote => "internal note", - order_vendornote => "vendor note" + order_vendornote => "vendor note", + ordernumber => '', }, num => { quantity => 24, -- 2.39.5