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)
  • Loading branch information
agritheory authored Jul 24, 2023
1 parent e3c87b4 commit 329c41c
Show file tree
Hide file tree
Showing 4 changed files with 1,868 additions and 2 deletions.
21 changes: 21 additions & 0 deletions check_run/check_run/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import frappe


Expand All @@ -7,3 +9,22 @@ def show_bank_account_number(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}


@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 Check Run {draft_check_run.name} and cannot be cancelled."
)
)
13 changes: 11 additions & 2 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 @@ -102,7 +102,16 @@
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
1 change: 1 addition & 0 deletions check_run/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,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 329c41c

Please sign in to comment.