From 6c55a4e7d47af52d2187f5f9ee44299074e0d9f2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 8 Jun 2026 16:53:01 +0100 Subject: [PATCH] Bug 42789: EDI ORDRSP cancellation should use Koha::Acquisition::Order->cancel() The process_ordrsp() function was calling C4::Acquisition::ModOrder() directly when processing a supplier cancellation, which only updated the order status fields and left associated items and purchase suggestions untouched. Replace with Koha::Acquisition::Order->cancel(), which mirrors the behaviour of manual cancellation via the acquisitions UI: - Deletes on-order items via safe_delete() with error capture - Reverts any linked purchase suggestion from ORDERED back to ACCEPTED - Updates orderstatus, cancellationreason and datecancellationprinted The delete_biblio option is intentionally omitted (defaults to false) as silent biblio deletion is not appropriate for an automated EDI flow. ModOrder is retained for the non-cancellation branch which only needs to update suppliers_report. Sponsored-by: OpenFifth Signed-off-by: Sharon Dugdale Signed-off-by: Kyle M Hall Signed-off-by: Pedro Amorim --- Koha/EDI.pm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 60499cd9ef..29bc28e5dd 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -54,6 +54,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; use Koha::AuthorisedValues; use Koha::Util::FrameworkPlugin qw( biblio_008 ); @@ -216,14 +217,12 @@ sub process_ordrsp { my $action = $line->action_notification(); if ( $action eq 'cancelled' ) { my $reason = $line->coded_orderline_text(); - ModOrder( - { - ordernumber => $ordernumber, - cancellationreason => $reason, - orderstatus => 'cancelled', - datecancellationprinted => dt_from_string()->ymd(), - } - ); + my $order = Koha::Acquisition::Orders->find($ordernumber); + if ($order) { + $order->cancel( { reason => $reason } ); + } else { + $logger->error("EDI ORDRSP: ordernumber $ordernumber not found, cannot process cancellation"); + } } else { # record order as due with possible further info my $report = $line->coded_orderline_text();