From d8fc369e38a7860a18afdfcf280c766c8e8cadfd Mon Sep 17 00:00:00 2001 From: l0gesh29 Date: Thu, 27 Nov 2025 14:19:32 +0530 Subject: [PATCH] fix: add validation for cancelled reposting entries --- erpnext/controllers/accounts_controller.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 3902b2f72028..e3669145f7a2 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -364,6 +364,24 @@ def _remove_references_in_repost_doctypes(self): for _doctype in repost_doctypes: dt = frappe.qb.DocType(_doctype) + + cancelled_entries = ( + frappe.qb.from_(dt) + .select(dt.parent, dt.parenttype) + .where((dt.voucher_type == self.doctype) & (dt.voucher_no == self.name) & (dt.docstatus == 2)) + .run(as_dict=True) + ) + + if cancelled_entries: + entries = "
".join([get_link_to_form(d.parenttype, d.parent) for d in cancelled_entries]) + + frappe.throw( + _( + "The following cancelled repost entries exist for {0}:

{1}

" + "Kindly delete these entries before continuing." + ).format(self.name, entries) + ) + rows = ( frappe.qb.from_(dt) .select(dt.name, dt.parent, dt.parenttype)