Skip to content

Commit

Permalink
feat: disallow cancellation of source documents selected for payment …
Browse files Browse the repository at this point in the history
…in draft CRs (#126) (#143)
  • Loading branch information
agritheory authored Aug 30, 2023
1 parent 079aa52 commit bddc888
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 111 deletions.
25 changes: 22 additions & 3 deletions check_run/check_run/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import json

import frappe


@frappe.whitelist()
def show_bank_account_number(doctype, docname):
doc = frappe.get_doc(doctype, docname)
routing_number = frappe.get_value('Bank', doc.bank, 'aba_number') or ''
account_number = doc.get_password('bank_account', raise_exception=False) or ''
return {'routing_number': routing_number, 'account_number': account_number}
routing_number = frappe.get_value("Bank", doc.bank, "aba_number") or ""
account_number = doc.get_password("bank_account", raise_exception=False) or ""
return {"routing_number": routing_number, "account_number": account_number}


@frappe.whitelist()
def disallow_cancellation_if_in_check_run(doc, method=None):
draft_check_runs = frappe.get_all("Check Run", ["name", "transactions"], {"docstatus": 0})
for draft_check_run in draft_check_runs:
transactions = [
t.get("ref_number") or t.get("name")
for t in json.loads(draft_check_run.transactions)
if t.get("pay")
]
if doc.name in transactions:
frappe.throw(
frappe._(
f"""This document is currently selected for payment in draft {frappe.get_desk_link('Check Run', draft_check_run.name)} and cannot be cancelled."""
)
)
29 changes: 14 additions & 15 deletions check_run/hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import __version__ as app_version
from . import __version__ as app_version # noqa: F401

app_name = "check_run"
app_title = "Check Run"
Expand Down Expand Up @@ -35,9 +35,9 @@

# include js in doctype views
doctype_js = {
'Employee': 'public/js/custom/employee_custom.js',
"Payment Entry": 'public/js/custom/payment_entry_custom.js',
"Supplier": 'public/js/custom/supplier_custom.js',
"Employee": "public/js/custom/employee_custom.js",
"Payment Entry": "public/js/custom/payment_entry_custom.js",
"Supplier": "public/js/custom/supplier_custom.js",
}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
Expand All @@ -51,7 +51,7 @@

# website user home page (by Role)
# role_home_page = {
# "Role": "home_page"
# "Role": "home_page"
# }

# Generators
Expand All @@ -65,7 +65,7 @@

# before_install = "check_run.install.before_install"
after_install = "check_run.customize.after_install"
after_migrate = 'check_run.customize.load_customizations'
after_migrate = "check_run.customize.load_customizations"

# Uninstallation
# ------------
Expand Down Expand Up @@ -95,9 +95,7 @@
# ---------------
# Override standard doctype classes

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

# Document Events
# ---------------
Expand All @@ -106,7 +104,12 @@
doc_events = {
"Payment Entry": {
"on_submit": "check_run.overrides.payment_entry.update_check_number",
}
},
"Purchase Invoice": {
"before_cancel": ["check_run.check_run.disallow_cancellation_if_in_check_run"]
},
"Expense Claim": {"before_cancel": ["check_run.check_run.disallow_cancellation_if_in_check_run"]},
"Journal Entry": {"before_cancel": ["check_run.check_run.disallow_cancellation_if_in_check_run"]},
}

# Scheduled Tasks
Expand Down Expand Up @@ -173,8 +176,4 @@
# For example: Role, Gender, etc.
# translated_search_doctypes = []

jinja = {
"methods": [
"frappe.contacts.doctype.address.address.get_default_address"
]
}
jinja = {"methods": ["frappe.contacts.doctype.address.address.get_default_address"]}
1 change: 1 addition & 0 deletions check_run/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def create_test_data():
create_invoices(settings)
config_expense_claim(settings)
create_employees(settings)
create_expense_claim(settings)
for month in range(1, 13):
create_payroll_journal_entry(settings)
settings.day = settings.day.replace(month=month)
Expand Down
Loading

0 comments on commit bddc888

Please sign in to comment.