From 8572e9192dd7261eee829b6f6a75f5be29780e64 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Nov 2023 14:56:06 +0100 Subject: [PATCH] Bug 28844: Adjust other calls --- Koha/Acquisition/Order.pm | 4 ++-- Koha/EDI.pm | 13 +++++-------- acqui/addorder.pl | 25 ++++++++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index eee73ce0533..d9b55d7a158 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -146,8 +146,8 @@ sub cancel { } # If ordered from a suggestion, revert the suggestion status to ACCEPTED - my $suggestion = Koha::Suggestions->find({ biblionumber => $self->biblionumber, status => "ORDERED" }); - if ( $suggestion and $suggestion->id ) { + my $suggestion = $self->suggestion; + if ( $suggestion && $suggestion->STATUS eq "ORDERED" ) { ModSuggestion( { suggestionid => $suggestion->id, diff --git a/Koha/EDI.pm b/Koha/EDI.pm index ceb9a2ccd41..f6b994877be 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -45,6 +45,7 @@ use Koha::Plugins; # Adds plugin dirs to @INC use Koha::Plugins::Handler; use Koha::Acquisition::Baskets; use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Orders; our $VERSION = 1.1; @@ -330,16 +331,12 @@ sub process_invoice { # ModReceiveOrder does not validate that $ordernumber exists validate here if ($order) { - # check suggestions - my $s = $schema->resultset('Suggestion')->search( - { - biblionumber => $order->biblionumber->biblionumber, - } - )->single; - if ($s) { + my $order_koha_object = Koha::Acquisition::Orders->find($ordernumber); + my $suggestion = $order_koha_object->suggestion; + if ($suggestion) { ModSuggestion( { - suggestionid => $s->suggestionid, + suggestionid => $suggestion->suggestionid, STATUS => 'AVAILABLE', } ); diff --git a/acqui/addorder.pl b/acqui/addorder.pl index de8d3648f89..01bfabc8eaf 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -330,17 +330,6 @@ if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { $orderinfo->{biblionumber}=$biblionumber; } - # change suggestion status if applicable - if ( my $suggestionid = $input->param('suggestionid') ) { - ModSuggestion( - { - suggestionid => $suggestionid, - biblionumber => $orderinfo->{biblionumber}, - STATUS => 'ORDERED', - } - ); - } - $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq ''; my $order; @@ -357,6 +346,20 @@ if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { $order->populate_with_prices_for_ordering(); $order->store; + # change suggestion status if applicable + if ( my $suggestionid = $input->param('suggestionid') ) { + # Double checking we are going to edit the correct suggestion + if ( $suggestionid == $order->suggestion->suggestion ) { + ModSuggestion( + { + suggestionid => $suggestionid, + biblionumber => $orderinfo->{biblionumber}, + STATUS => 'ORDERED', + } + ); + } + } + # Log the order creation if (C4::Context->preference("AcquisitionLog")) { my $infos = {}; -- 2.34.1