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)