diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index fb809473962..e2042c59ad7 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -365,6 +365,24 @@ class AccountsController(TransactionBase): 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)