Skip to content

Commit

Permalink
refactor: handle PR's in advance stage
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Nov 7, 2024
1 parent cda7800 commit c104b0f
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,21 @@ def get_amount(ref_doc, payment_account=None):
frappe.throw(_("Payment Entry is already created"))


def get_irequest_status(payment_requests: None | list = None) -> list:
IR = frappe.qb.DocType("Integration Request")
res = []
if payment_requests:
res = (
frappe.qb.from_(IR)
.select(IR.name)
.where(IR.reference_doctype.eq("Payment Request"))
.where(IR.reference_docname.isin(payment_requests))
.where(IR.status.isin(["Authorized", "Completed"]))
.run(as_dict=True)
)
return res


def cancel_old_payment_requests(ref_dt, ref_dn):
PR = frappe.qb.DocType("Payment Request")

Expand All @@ -708,14 +723,17 @@ def cancel_old_payment_requests(ref_dt, ref_dn):
.where(PR.status.isin(["Draft", "Requested"]))
.run(as_dict=True)
):
for x in res:
doc = frappe.get_doc("Payment Request", x.name)
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")
if get_irequest_status([x.name for x in res]):
frappe.throw(_("Another Payment Request is already processed."))
else:
for x in res:
doc = frappe.get_doc("Payment Request", x.name)
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

0 comments on commit c104b0f

Please sign in to comment.