Skip to content

Commit

Permalink
feat: validate docstatus of selected invoices still saved/submitted (#44
Browse files Browse the repository at this point in the history
)

* feat: validate docstatus of selected invoices still saved/submitted

* refactor: moved validation code for cancelled transactions to function
  • Loading branch information
HKuz authored Feb 15, 2023
1 parent af2ebf3 commit 78b3e25
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()) + '<br>'
frappe.throw(frappe._(
f"The following document(s) have been cancelled, please remove them from Check Run to continue:<br>{invalid_records}"
))

@frappe.whitelist()
def validate_last_check_number(self, check_number=None):
if self.ach_only().ach_only:
Expand Down

0 comments on commit 78b3e25

Please sign in to comment.