From 78b3e2580e200ce60211ed44d20651f68546eeae Mon Sep 17 00:00:00 2001 From: Heather Kusmierz Date: Wed, 15 Feb 2023 16:42:02 -0500 Subject: [PATCH] feat: validate docstatus of selected invoices still saved/submitted (#44) * feat: validate docstatus of selected invoices still saved/submitted * refactor: moved validation code for cancelled transactions to function --- .../check_run/doctype/check_run/check_run.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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: