@@ -, +, @@ --- Koha/Acquisition/Order.pm | 4 ++-- Koha/EDI.pm | 13 +++++-------- acqui/addorder.pl | 25 ++++++++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) --- a/Koha/Acquisition/Order.pm +++ a/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, --- a/Koha/EDI.pm +++ a/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', } ); --- a/acqui/addorder.pl +++ a/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 = {}; --