From 917a21b989744774796c42d2e14e7793fb13805e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:26:32 +0530 Subject: [PATCH] fix: not able to delete cancelled delivery note (backport #40508) (#40510) fix: not able to delete cancelled delivery note (#40508) (cherry picked from commit 7695759f3ce9c3acb1db986c6cd3a82d520289c5) Co-authored-by: rohitwaghchaure --- .../doctype/work_order/work_order.js | 2 ++ .../delivery_note/test_delivery_note.py | 21 +++++++++++++++++++ erpnext/stock/doctype/pick_list/pick_list.py | 6 +++++- .../serial_and_batch_bundle.py | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 42f69438aef..70e803dbba1 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -9,6 +9,8 @@ frappe.ui.form.on("Work Order", { "Job Card": "Create Job Card", }; + frm.ignore_doctypes_on_cancel_all = ["Serial and Batch Bundle"]; + // Set query for warehouses frm.set_query("wip_warehouse", function () { return { diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index f9341393ad0..24544070d3b 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -1097,9 +1097,30 @@ class TestDeliveryNote(FrappeTestCase): dn.load_from_db() batch_no = get_batch_from_bundle(dn.packed_items[0].serial_and_batch_bundle) + packed_name = dn.packed_items[0].name self.assertTrue(batch_no) + dn.cancel() + + # Cancel the reposting entry + reposting_entries = frappe.get_all("Repost Item Valuation", filters={"docstatus": 1}) + for entry in reposting_entries: + doc = frappe.get_doc("Repost Item Valuation", entry.name) + doc.cancel() + doc.delete() + + frappe.db.set_single_value("Accounts Settings", "delete_linked_ledger_entries", 1) + + dn.reload() + dn.delete() + + bundle = frappe.db.get_value( + "Serial and Batch Bundle", {"voucher_detail_no": packed_name}, "name" + ) + self.assertFalse(bundle) + frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1) + frappe.db.set_single_value("Accounts Settings", "delete_linked_ledger_entries", 0) def test_payment_terms_are_fetched_when_creating_sales_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 8a1f79d4a27..627520c1dcd 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -184,7 +184,11 @@ class PickList(Document): def delink_serial_and_batch_bundle(self): for row in self.locations: - if row.serial_and_batch_bundle: + if ( + row.serial_and_batch_bundle + and frappe.db.get_value("Serial and Batch Bundle", row.serial_and_batch_bundle, "docstatus") + == 1 + ): frappe.db.set_value( "Serial and Batch Bundle", row.serial_and_batch_bundle, diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 9a7395fc667..1fb4969e306 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -778,6 +778,10 @@ class SerialandBatchBundle(Document): or_filters=or_filters, ) + if not vouchers and self.voucher_type == "Delivery Note": + frappe.db.set_value("Packed Item", self.voucher_detail_no, "serial_and_batch_bundle", None) + return + for voucher in vouchers: if voucher.get("current_serial_and_batch_bundle"): frappe.db.set_value(self.child_table, voucher.name, "current_serial_and_batch_bundle", None)