Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disallow cancellation of source documents selected for payment … #126

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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