Skip to content

Commit

Permalink
Merge pull request #150 from agritheory/read_only
Browse files Browse the repository at this point in the history
feat: add read_only decorator
  • Loading branch information
HKuz authored Sep 8, 2023
2 parents 5831fb8 + aaca764 commit 73d459d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions check_run/check_run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


@frappe.whitelist()
@frappe.read_only()
def show_bank_account_number(doctype: str, docname: str) -> dict:
doc = frappe.get_doc(doctype, docname)
routing_number = frappe.get_value("Bank", doc.bank, "aba_number") or ""
Expand Down
7 changes: 7 additions & 0 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@


class CheckRun(Document):
@frappe.read_only()
def onload(self: Self) -> None:
if self.is_new():
return
Expand Down Expand Up @@ -109,6 +110,7 @@ def set_default_dates(self: Self) -> None:
if not self.end_date: # type: ignore # datetime or None
self.end_date = getdate()

@frappe.read_only()
def filter_transactions(self: Self) -> None:
if not self.get("transactions"):
return
Expand All @@ -122,6 +124,7 @@ def filter_transactions(self: Self) -> None:
if not t["mode_of_payment"]:
frappe.throw(frappe._(f"Mode of Payment Required: {t['party_name']} {t['ref_number']}"))

@frappe.read_only()
def not_outstanding_or_cancelled(self: Self, transaction: dict) -> bool:
filters = {
"name": transaction["name"]
Expand Down Expand Up @@ -222,6 +225,7 @@ def build_nacha_file(self: Self, settings: CheckRunSettings) -> str:
return build_nacha_file_from_payment_entries(self, payment_entries, settings)

@frappe.whitelist()
@frappe.read_only()
def ach_only(self: Self) -> bool:
transactions = json.loads(self.transactions) if self.transactions else []
ach_only = frappe._dict({"ach_only": True, "print_checks_only": True})
Expand Down Expand Up @@ -451,6 +455,7 @@ def confirm_print(docname: str) -> None:


@frappe.whitelist()
@frappe.read_only()
def get_entries(doc: CheckRun | str) -> dict:
doc = frappe._dict(json.loads(doc)) if isinstance(doc, str) else doc
if isinstance(doc.end_date, str):
Expand Down Expand Up @@ -621,6 +626,7 @@ def get_entries(doc: CheckRun | str) -> dict:


@frappe.whitelist()
@frappe.read_only()
def get_balance(doc: CheckRun | str) -> str:
doc = frappe._dict(json.loads(doc)) if isinstance(doc, str) else doc
if not doc.bank_account or not doc.posting_date:
Expand Down Expand Up @@ -780,6 +786,7 @@ def get_address(party: str, party_type: str, doctype: str, name: str) -> str:


@frappe.whitelist()
@frappe.read_only()
def ach_only(docname: str) -> dict:
if not frappe.db.exists("Check Run", docname):
return {"ach_only": False, "checks_only": False}
Expand Down

0 comments on commit 73d459d

Please sign in to comment.