Skip to content

Commit

Permalink
feat: add Canadian DFI Routing Number validation for bank
Browse files Browse the repository at this point in the history
  • Loading branch information
HKuz authored and agritheory committed Feb 15, 2023
1 parent 1e86c00 commit b4d9df9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions check_run/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
# ---------------
# Override standard doctype classes

# override_doctype_class = {
# "ToDo": "custom_app.overrides.CustomToDo"
# }
override_doctype_class = {
"Bank": "check_run.overrides.bank.CustomBank"
}

# Document Events
# ---------------
Expand Down
Empty file added check_run/overrides/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions check_run/overrides/bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import frappe
from frappe import _
from frappe.utils import cint, flt

from erpnext.accounts.doctype.bank.bank import Bank


class CustomBank(Bank):
def validate(self):
# Canadian banking institutions limit DFI Routing Numbers to 8 characters
addresses = frappe.qb.DocType('Address')
dls = frappe.qb.DocType('Dynamic Link')

countries_qb = (
frappe.qb.from_(addresses)
.inner_join(dls)
.on(addresses.name == dls.parent)
.select(addresses.country)
.where(dls.parenttype == 'Address')
.where(dls.link_doctype == 'Bank')
.where(dls.link_name == self.name)
)

countries = frappe.db.sql(
countries_qb,
as_dict=True,
pluck='country'
)
if 'Canada' in countries:
if len(self.aba_number) > 8:
frappe.throw(_("This Bank is linked to at least one Canadian address. Canadian banking institutions require the ABA Number must not exceed 8 characters."))
return

0 comments on commit b4d9df9

Please sign in to comment.