[Bug 43876] New: CancelReceipt deletes items with raw SQL: no deleteditems copy, no reindex, no logging
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43876 Bug ID: 43876 Summary: CancelReceipt deletes items with raw SQL: no deleteditems copy, no reindex, no logging 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: adolfo.rodriguez@xercode.es QA Contact: testopia@bugs.koha-community.org Target Milestone: --- When a basket creates items on receiving (effective_create_items eq 'receiving'), cancelling a receipt (C4::Acquisition::CancelReceipt) deletes those items with a raw SQL DELETE in _cancel_items_receipt: DELETE FROM items, aqorders_items USING items, aqorders_items WHERE items.itemnumber = ? AND aqorders_items.itemnumber = ? Because Koha::Item->delete is bypassed: - no copy of the item is kept in deleteditems - the bibliographic record is not reindexed, so the deleted items are still shown in the search results (Elasticsearch and Zebra) - nothing is written to the cataloguing log - the after_item_action plugin hook (action 'delete') is not called - the real-time holds queue is not updated - an item group left empty is not deleted To reproduce: 1. Create a basket with "Create items when: receiving an order". 2. Add an order with quantity 2, close the basket and receive it. Two items are created and shown in the catalog search results. 3. Cancel the receipt. 4. The items are gone from the items table, but they are not in deleteditems, there is no DELETE entry in the cataloguing log, and the record still shows the items in the search results. -- 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=43876 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff --- Comment #1 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Patch attached. The test plan is in the commit message. The items are still deleted without the safe_delete checks, as before; only the deletion mechanism changes. -- 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=43876 --- Comment #2 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 208631 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208631&action=edit Bug 43876: Use Koha::Item->delete when cancelling a receipt When the basket creates items on receiving, CancelReceipt deleted those items with a raw SQL DELETE in _cancel_items_receipt. This bypassed Koha::Item->delete, so: - no copy of the item was kept in deleteditems - the bibliographic record was not reindexed, so the deleted items were still shown in the search results - nothing was written to the cataloguing log - the after_item_action plugin hook was not called - the real-time holds queue was not updated - an item group left empty was not deleted This patch deletes each item with move_to_deleted and Koha::Item->delete, and removes the aqorders_items row explicitly (that table has no foreign key on items, so it is not cleaned up by the item deletion). The record is reindexed, and the holds queue updated, once after all the items have been deleted. As before, the items are deleted without checking whether they can be safely deleted (checkouts, holds...): only the deletion mechanism changes. Steps to follow: 1. Make sure the search index is updated automatically (koha-es-indexer running, or the Zebra daemon), and enable CataloguingLog. 2. Create a basket with "Create items when: receiving an order", add an order with quantity 2, close the basket and receive the order. Two items are created and are shown in the catalog search results. 3. Cancel the receipt. The items are gone from the record details page, but: - they are not in deleteditems: SELECT * FROM deleteditems WHERE biblionumber = <biblionumber>; - there is no DELETE entry for them in the cataloguing log (Tools > Log viewer > Cataloging) - the catalog search results still show the items 4. Apply the patch and restart Plack if running under it. 5. Repeat steps 2 and 3 with a new order. Now the items are moved to deleteditems, the cataloguing log shows a DELETE entry for each item, and the search results no longer show them. 6. Receive only 1 item of an order with quantity 2 (the order is split) and cancel that receipt: the item is moved to deleteditems and the original order is pending again with quantity 2. 7. With a basket that creates items on ordering, receive an order and cancel the receipt: the item is not deleted and is linked again to the pending order (no change in behaviour). 8. prove t/db_dependent/Acquisition/CancelReceipt.t Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org