Skip to content

Commit

Permalink
fix: not able to delete cancelled delivery note
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Mar 18, 2024
1 parent 6d47b8a commit 879db5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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
Expand Up @@ -1108,9 +1108,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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 879db5d

Please sign in to comment.