[Bug 44256] New: EDI ORDRSP: do not cancel received/invoiced lines and report item deletion failures to the librarian
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Bug ID: 44256 Summary: EDI ORDRSP: do not cancel received/invoiced lines and report item deletion failures to the librarian Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Acquisitions Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Blocks: 41852 Target Milestone: --- When an EDI ORDRSP message cancels an order line that has already been received or invoiced, Koha::EDI::process_ordrsp still calls Koha::Acquisition::Order->cancel() on it. Nothing is reported to the librarian. Confirmed on the 25.11 line with a rolled-back test: a line with quantity 2 / quantityreceived 2 and orderstatus 'complete' (Spent = 20 on its fund) was cancelled by an ORDRSP. Afterwards its status is 'cancelled', datecancellationprinted is set, its on-order items are deleted and the fund's Spent figure dropped to 0. Both GetBudgetSpent and GetBudgetOrdered exclude lines with datecancellationprinted set, so money that has really been spent silently disappears from the fund. Separately, Koha::Acquisition::Order->cancel() records item deletion failures (book_on_loan, book_reserved, item_has_holds, last_item_for_hold, ...) as messages via add_message(), and process_ordrsp ignores them. For example, with a hold on an on-order item the line is cancelled, the item stays "Not for loan (On order)", and nothing is logged or shown. This is the likely remaining symptom behind bug 44187. Expected behaviour: * Before cancelling, process_ordrsp checks whether the order line has been receipted or invoiced (quantityreceived > 0, orderstatus complete or partial, or an invoiceid set). If so, the cancellation is NOT applied: the line is left untouched and a warning is recorded against the ORDRSP message with $response_message->add_to_edifact_errors(), as process_invoice() already does for invoice lines referencing complete orders (details give the ordernumber, the supplier's reason and the received quantity/date). Also log it with Koha::Logger. * An already-cancelled line is left alone (cancel is idempotent) without raising an error. * After ->cancel(), any messages it returned (error_delitem with reason, error_delbiblio*) are written to edifact_errors for the ORDRSP message and to the EDI logger instead of being dropped, so the librarian can see which items could not be removed and why. Do not croak; carry on with the remaining lines. * Set the ORDRSP message status to 'error' when anything was reported, in the same way process_invoice() avoids overwriting an error status, so it is visible on the EDI messages page. * Consider whether the librarian-facing text should appear on the existing EDI messages/errors view or whether that view needs a small change to list ORDRSP errors (edifact_errors.invoicenumber is nullable, so it can be left empty here; check how the existing template displays errors). Interaction with other bugs: partial cancellation is bug 44255 (a partially received line with outstanding copies is a legitimate target for a partial cancel, so the check there should compare the cancelled quantity against the outstanding quantity, not just reject everything with quantityreceived > 0). Related: 42788, 42789, 44187. Tests (t/db_dependent/Koha/EDI.t, 'process_ordrsp'): cancel of a received line is rejected, line unchanged, fund Spent unchanged and an edifact_errors row exists; cancel of an already-cancelled line adds no error; cancel with an item that has a hold leaves the item, cancels the line and records an error with the reason; warnings must not break Test::NoWarnings. Test plan (needs an ORDRSP file or a unit test): 1. Order a line, receive it fully (or process an invoice), and note the fund's Spent. 2. Process an ORDRSP cancelling that line. 3. Before the patch: line cancelled, Spent drops. After: line unchanged, Spent unchanged, an error is listed against the ORDRSP message. 4. Place a hold on an on-order item of another line and process an ORDRSP cancelling it. After the patch the item remains and the reason is reported to the librarian. Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41852 [Bug 41852] Modernize EDI support in Koha -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk Status|NEW |ASSIGNED -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |44187 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44187 [Bug 44187] EDIFACT: Cancelled orderline items should be automatically deleted (as well as encumbrance released) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Evidence from a production system running 25.11 with an active EDI vendor account, which I've been inspecting (aggregate figures only). ORDRSP cancellations, May 2025 to Nov 2026: * 830 line-level cancels (action 2). 792 match an existing order and every one of those is status cancelled with datecancellationprinted set, so fund Ordered is released correctly (see my correction on bug 42788). * 38 reference ordernumbers that do not exist in aqorders (older, low numbers; latest Jan 2026). process_ordrsp logs these and moves on. * 70 orders were cancelled by more than one ORDRSP. Harmless, cancel() is idempotent. Item deletion failures are the visible problem here. Items on ORDRSP-cancelled lines are deleted from July 2026 onwards (bug 42789 live), with a handful of exceptions. Since July, 10 items on cancelled lines survive. 9 of them are the only item on a biblio that has a hold, so Koha::Item::safe_delete refuses them as last_item_for_hold. process_ordrsp discards the message that ->cancel() adds for this, so nothing is logged and nothing is shown to the librarian. The items stay Not for loan (On order) and keep attracting holds. (The tenth has no hold and I don't know why it survived; it was cancelled on the first day items started being deleted, so it may predate the upgrade.) That is exactly the reporting this bug asks for: the ->cancel() messages (error_delitem with its reason) should be recorded against the ORDRSP message and logged, and the message status set to error, so staff can see which items need handling by hand. I'd also like to cover the fallback for such items in bug 44187 (set a configurable item status when the item cannot be deleted). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on|44187 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44187 [Bug 44187] EDIFACT: Cancelled orderline items should be automatically deleted (as well as encumbrance released) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44187 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44187 [Bug 44187] EDIFACT: Cancelled orderline items should be automatically deleted (as well as encumbrance released) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 --- Comment #2 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 212557 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212557&action=edit Bug 44256: Don't cancel received lines from ORDRSP and report item deletion failures An ORDRSP cancellation was applied to any order line, including lines that had already been received or invoiced. Cancelling such a line sets its cancellation date, which removes it from both the fund's ordered and spent totals, so money that had really been spent silently disappeared from the fund. Separately, items that Koha::Acquisition::Order->cancel() could not delete (for example the last item on a record with a hold) were only written to the EDI log, so the librarian was never told. process_ordrsp now: - leaves an already received or invoiced line untouched (quantityreceived, an invoiceid or a complete status) and records why - skips a line that is already cancelled, as suppliers repeat cancellations - records item deletion failures from cancel() - stores each of these as an edifact_errors row on the ORDRSP message and sets the message status to 'error', so it appears with errors on the EDI messages page The outstanding remainder of a part-received line (status partial, nothing received against it) can still be cancelled. To test: 1. prove t/db_dependent/Koha/EDI.t 2. Receive an order line, then process an ORDRSP cancelling it: the line stays as it was, the fund's spent total is unchanged and the message is listed with errors on Acquisitions > EDIFACT messages. 3. Place a hold on the only on-order item of a line, then process an ORDRSP cancelling it: the line is cancelled, the item remains and the error says which item and why. Sponsored-by: OpenFifth <https://openfifth.co.uk/> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 --- Comment #3 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Two clarifications to my earlier comments on this bug. 1. Item deletion failures from Order->cancel() are already written to the EDI log on main, since the bug 42789 QA follow-ups. The system I inspected is on a branch without those follow-ups, which is why nothing was logged there. This bug adds the part that is still missing: recording them against the message, with the status set to error, so the librarian sees them on the EDI messages page. 2. The description says received or invoiced lines are those with status complete or partial. The patch uses quantityreceived > 0, an invoiceid, or status complete. A line with status partial and nothing received is the outstanding remainder of a split receipt (the received copies are moved to their own line), and it is a legitimate target for a supplier cancel. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|44187 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44187 [Bug 44187] EDI ORDRSP cancellations: cancel holds, delete items and notify staff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |RESOLVED Resolution|--- |DUPLICATE --- Comment #4 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- This work is now patch 1 of the patch set on bug 44187, so reviewers have a single bug for the whole automated ORDRSP cancellation workflow. Closing this one as a duplicate; the patch attached here is obsolete in favour of the set on 44187. *** This bug has been marked as a duplicate of bug 44187 *** -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44256 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212557|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org