diff --git a/check_run/check_run/doctype/check_run/check_run.py b/check_run/check_run/doctype/check_run/check_run.py
index edd9fbe6..3d0b36d2 100644
--- a/check_run/check_run/doctype/check_run/check_run.py
+++ b/check_run/check_run/doctype/check_run/check_run.py
@@ -45,6 +45,7 @@ def validate(self):
self.get_default_payable_account()
self.set_default_dates()
else:
+ self.validate_transactions()
self.validate_last_check_number()
def on_cancel(self):
@@ -90,6 +91,23 @@ def set_default_dates(self):
if not self.end_date:
self.end_date = getdate()
+ def validate_transactions(self):
+ if not self.get('transactions'):
+ return
+ selected = [txn for txn in json.loads(self.get('transactions')) if txn['pay']]
+ wrong_status = []
+ for t in selected:
+ if frappe.get_value(t['doctype'], filters=t['name'], fieldname='docstatus') != 1:
+ wrong_status.append({'party_name': t['party_name'], 'ref_number': t['ref_number'] or '', 'name': t['name']})
+ if len(wrong_status) < 1:
+ return
+ invalid_records = ''
+ for invalid_record in wrong_status:
+ invalid_records += ' '.join(invalid_record.values()) + '
'
+ frappe.throw(frappe._(
+ f"The following document(s) have been cancelled, please remove them from Check Run to continue:
{invalid_records}"
+ ))
+
@frappe.whitelist()
def validate_last_check_number(self, check_number=None):
if self.ach_only().ach_only: