Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not able to delete cancelled delivery note (backport #40508) #40510

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions erpnext/manufacturing/doctype/work_order/work_order.js
Original file line number Diff line number Diff line change
@@ -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 {
21 changes: 21 additions & 0 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
@@ -1097,9 +1097,30 @@ def test_delivery_note_bundle_with_batched_item(self):
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 (
6 changes: 5 additions & 1 deletion erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
@@ -184,7 +184,11 @@ def on_cancel(self):

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,
Original file line number Diff line number Diff line change
@@ -778,6 +778,10 @@ def delink_refernce_from_voucher(self):
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)