Skip to content

Commit

Permalink
refactor: cancel irequests directly upon PR cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Nov 4, 2024
1 parent fec0752 commit de8787f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
38 changes: 34 additions & 4 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ def cancel_old_payment_requests(ref_dt, ref_dn):
doc.flags.ignore_permissions = True
doc.cancel()

if ireqs := get_irequests_of_payment_request(doc.name):
for ireq in ireqs:
frappe.db.set_value("Integration Request", ireq.name, "status", "Cancelled")


def get_existing_payment_request_amount(ref_dt, ref_dn, statuses: list | None = None) -> list:
"""
Expand Down Expand Up @@ -952,17 +956,43 @@ def get_open_payment_requests_query(doctype, txt, searchfield, start, page_len,
]


def clear_integration_requests_of_cancelled_payment_requests():
def get_irequests_of_payment_request(doc: str | None = None) -> list:
res = []
if doc:
res = frappe.db.get_all(
"Integration Request",
{
"reference_doctype": "Payment Request",
"reference_docname": doc,
"status": "Queued",
},
)
return res


def get_all_irequests_of_cancelled_payment_request() -> list:
res = []

pr = qb.DocType("Payment Request")
if payment_requests := qb.from_(pr).select(pr.name).where(pr.docstatus.eq(2)).run(as_list=True):
#
payment_requests = [x[0] for x in payment_requests]
integration_requests = frappe.db.get_all(

res = frappe.db.get_all(
"Integration Request",
{
"reference_doctype": "Payment Request",
"reference_docname": ["in", payment_requests],
"status": "Queued",
},
)
for ireq in integration_requests:
frappe.delete_doc("Integration Request", ireq.name, force=1)
return res


def cancel_integration_requests_of_cancelled_payment_requests():
"""
Primarily used by background job
"""
integration_requests = get_all_irequests_of_cancelled_payment_request()
for ireq in integration_requests:
frappe.db.set_value("Integration Request", ireq.name, "status", "Cancelled")
2 changes: 1 addition & 1 deletion erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
"0/15 * * * *": [
"erpnext.manufacturing.doctype.bom_update_log.bom_update_log.resume_bom_cost_update_jobs",
"erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.trigger_reconciliation_for_queued_docs",
"erpnext.accounts.doctype.payment_request.payment_request.clear_integration_requests_of_cancelled_payment_requests",
"erpnext.accounts.doctype.payment_request.payment_request.cancel_integration_requests_of_cancelled_payment_requests",
],
"0/30 * * * *": [
"erpnext.utilities.doctype.video.video.update_youtube_data",
Expand Down

0 comments on commit de8787f

Please sign in to comment.