Skip to content

Commit

Permalink
fix: move bank validation out of override class into hook (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
agritheory authored Aug 30, 2023
1 parent bddc888 commit f07ad5a
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 64 deletions.
28 changes: 14 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ repos:
rev: v4.3.0
hooks:
- id: trailing-whitespace
files: "frappe.*"
exclude: ".*json$|.*txt$|.*csv|.*md|.*svg"
files: 'frappe.*'
exclude: '.*json$|.*txt$|.*csv|.*md|.*svg'
- id: check-yaml
- id: no-commit-to-branch
args: ['--branch', 'develop']
Expand Down Expand Up @@ -37,22 +37,22 @@ repos:
types_or: [javascript]
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
frappe/public/dist/.*|
.*node_modules.*|
.*boilerplate.*|
frappe/www/website_script.js|
frappe/templates/includes/.*|
frappe/public/js/lib/.*
)$
(?x)^(
frappe/public/dist/.*|
.*node_modules.*|
.*boilerplate.*|
frappe/www/website_script.js|
frappe/templates/includes/.*|
frappe/public/js/lib/.*
)$
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear',]
additional_dependencies: ['flake8-bugbear']

ci:
autoupdate_schedule: weekly
skip: []
submodules: false
autoupdate_schedule: weekly
skip: []
submodules: false
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ module.exports = {
trailingComma: 'es5',
useTabs: true,
vueIndentScriptAndStyle: false,
}
}
4 changes: 1 addition & 3 deletions check_run/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@

__version__ = '14.0.0'

__version__ = "14.0.0"
2 changes: 0 additions & 2 deletions check_run/check_run/doctype/check_run/test_check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@

class TestCheckRun(unittest.TestCase):
pass


Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import frappe
from frappe.model.document import Document


class CheckRunSettings(Document):
pass


@frappe.whitelist()
def create(company, bank_account, pay_to_account):
crs =frappe.new_doc('Check Run Settings')
crs = frappe.new_doc("Check Run Settings")
crs.company = company
crs.bank_account = bank_account
crs.pay_to_account = pay_to_account
crs.save()
return crs.name
return crs.name
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# import frappe
import unittest


class TestCheckRunSettings(unittest.TestCase):
pass
22 changes: 14 additions & 8 deletions check_run/check_run/report/positive_pay/positive_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

import frappe


def execute(filters=None):
print(filters)
return get_columns(filters), get_data(filters)


def get_columns(filters):
return [
{
"label": frappe._("Check Date"),
"fieldname": "check_date",
"fieldtype": "Date",
"width": "150px"
"width": "150px",
},
{
"label": frappe._("Check Number"),
Expand All @@ -29,8 +31,10 @@ def get_columns(filters):
},
]


def get_data(filters):
return frappe.db.sql("""
return frappe.db.sql(
"""
SELECT
`tabPayment Entry`.reference_no AS check_number,
`tabPayment Entry`.reference_date AS check_date,
Expand All @@ -44,9 +48,11 @@ def get_data(filters):
AND `tabPayment Entry`.mode_of_payment = 'Check'
AND `tabPayment Entry`.docstatus = 1
ORDER BY check_date
""", {
'start_date': filters.start_date,
'end_date': filters.end_date,
'bank_account': filters.bank_account
}, as_dict=True)

""",
{
"start_date": filters.start_date,
"end_date": filters.end_date,
"bank_account": filters.bank_account,
},
as_dict=True,
)
3 changes: 2 additions & 1 deletion check_run/config/desktop.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from frappe import _


def get_data():
return [
{
"module_name": "Check Run",
"color": "grey",
"icon": "octicon octicon-file-directory",
"type": "module",
"label": _("Check Run")
"label": _("Check Run"),
}
]
1 change: 1 addition & 0 deletions check_run/config/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
# headline = "App that does everything"
# sub_heading = "Yes, you got that right the first time, everything"


def get_context(context):
context.brand_html = "Check Run"
4 changes: 2 additions & 2 deletions check_run/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
# DocType Class
# ---------------
# Override standard doctype classes

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

# Document Events
# ---------------
# Hook on document methods and events

doc_events = {
"Bank": {"validate": ["check_run.overrides.bank.validate"]},
"Payment Entry": {
"on_submit": "check_run.overrides.payment_entry.update_check_number",
},
Expand Down
50 changes: 23 additions & 27 deletions check_run/overrides/bank.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
import frappe
from frappe import _
from frappe.utils import cint, flt

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

@frappe.whitelist()
def validate(doc, method=None):
# Canadian banking institutions limit DFI Routing Numbers to 8 characters
addresses = frappe.qb.DocType("Address")
dls = frappe.qb.DocType("Dynamic Link")

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 == doc.name)
)

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
countries = frappe.db.sql(countries_qb, as_dict=True, pluck="country")
if "Canada" in countries:
if len(doc.aba_number) > 8:
frappe.throw(
frappe._(
"This Bank is linked to at least one Canadian address. Canadian banking institutions require the ABA Number must not exceed 8 characters."
)
)
return
10 changes: 7 additions & 3 deletions check_run/public/js/check_run/CheckRun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,17 @@ export default {
},
methods: {
transactionUrl: transaction => {
if(transaction.doctype !== 'Journal Entry'){
if (transaction.doctype !== 'Journal Entry') {
return encodeURI(
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${transaction.name}`
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${
transaction.name
}`
)
} else {
return encodeURI(
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${transaction.ref_number}`
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${
transaction.ref_number
}`
)
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"version-14"
]
}
}
}

0 comments on commit f07ad5a

Please sign in to comment.