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

Remove paid document on Process check run #202

Merged
merged 3 commits into from
Feb 6, 2024
Merged
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
39 changes: 32 additions & 7 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,18 @@ def process_check_run(self: Self) -> None:
self.run_method("validate")
self.status = "Submitting"
self.filter_transactions()
transactions = [t for t in json.loads(self.transactions) if t.get("pay")]
if len(transactions) < 1:
frappe.throw(frappe._("You must select at least one Invoice to pay."))
transactions = [
t
for t in json.loads(self.transactions)
if t.get("pay") and not self.not_outstanding_or_cancelled(t)
]
if not len(transactions):
frappe.msgprint(
"Please check; maybe you have not selected any document to pay, or the selected document has already been paid.<br><br>Kindly refresh the page."
)
return
# if len(transactions) < 1:
# frappe.throw(frappe._("You must select at least one Invoice to pay."))
self.print_count = 0
if self.ach_only().ach_only:
self.initial_check_number = "" # type: ignore
Expand Down Expand Up @@ -490,7 +499,14 @@ def get_entries(doc: CheckRun | str) -> dict:
if frappe.db.exists("Check Run", doc.name):
db_doc = frappe.get_doc("Check Run", doc.name)
if doc.end_date == db_doc.end_date and db_doc.transactions:
return {"transactions": json.loads(db_doc.transactions), "modes_of_payment": modes_of_payment}
if db_doc.docstatus == 0:
outstanding_transaction = []
for row in json.loads(db_doc.transactions):
if not db_doc.not_outstanding_or_cancelled(row):
outstanding_transaction.append(row)
else:
outstanding_transaction = json.loads(db_doc.transactions)
return {"transactions": outstanding_transaction, "modes_of_payment": modes_of_payment}

company = doc.company
pay_to_account = doc.pay_to_account
Expand Down Expand Up @@ -644,7 +660,9 @@ def get_entries(doc: CheckRun | str) -> dict:
attachment
for attachment in get_attachments(transaction.doctype, doc_name)
if attachment.file_url.endswith(".pdf")
] or [{"file_name": doc_name, "file_url": f"/app/Form/{transaction.doctype}/{doc_name}"}]
] or [
{"file_name": doc_name, "file_url": f"/app/Form/{transaction.doctype}/{doc_name}"}
]

if settings and settings.pre_check_overdue_items:
if transaction.due_date < doc.posting_date:
Expand All @@ -661,8 +679,15 @@ def get_entries(doc: CheckRun | str) -> dict:
transaction.mode_of_payment = (
frappe.get_value("Employee", transaction.party, "mode_of_payment") or settings.journal_entry
)

return {"transactions": transactions, "modes_of_payment": modes_of_payment}
# Process Unpaid Transaction
# start
outstanding_transaction = []
db_doc = frappe.get_doc("Check Run", doc.name)
for row in transactions:
if not db_doc.not_outstanding_or_cancelled(row):
outstanding_transaction.append(row)
# end
return {"transactions": outstanding_transaction, "modes_of_payment": modes_of_payment}


@frappe.whitelist()
Expand Down
Loading