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.