From 290dc7d2b23bddf911328a5c7af01c13bada097c Mon Sep 17 00:00:00 2001
From: Abdeali Chharchhoda
Date: Mon, 22 Jul 2024 15:32:07 +0530
Subject: [PATCH] fix: remove bug
---
.../doctype/payment_request/payment_request.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index 9afb5fb000b..4d8e6bf800a 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -467,6 +467,7 @@ def make_payment_request(**args):
{"reference_doctype": args.dt, "reference_name": args.dn, "docstatus": 0},
)
+ # fetches existing payment request `grand_total` amount
existing_payment_request_amount = get_existing_payment_request_amount(args.dt, args.dn)
if existing_payment_request_amount:
@@ -484,7 +485,6 @@ def make_payment_request(**args):
args["payment_request_type"] = (
"Outward" if args.get("dt") in ["Purchase Order", "Purchase Invoice"] else "Inward"
)
-
pr.update(
{
"payment_gateway_account": gateway_account.get("name"),
@@ -569,15 +569,23 @@ def get_amount(ref_doc, payment_account=None):
return grand_total
-def get_existing_payment_request_amount(ref_dt, ref_dn):
+def get_existing_payment_request_amount(ref_dt, ref_dn, only_paid=False):
"""
- Get the total amount of `Paid` / `Partially Paid` payment requests against a document.
+ Return the total amount of Payment Requests against a reference document. \n
+ If `only_paid` is True, it will return the total amount of paid Payment Requests. \n
+ Else, it will return the total amount of all Payment Requests.
"""
+
PR = frappe.qb.DocType("Payment Request")
+ if only_paid:
+ select = Sum(PR.grand_total - PR.outstanding_amount)
+ else:
+ select = Sum(PR.grand_total)
+
response = (
frappe.qb.from_(PR)
- .select(Sum(PR.grand_total - PR.outstanding_amount))
+ .select(select)
.where(PR.reference_doctype == ref_dt)
.where(PR.reference_name == ref_dn)
.where(PR.docstatus == 1)
@@ -715,7 +723,7 @@ def get_dummy_message(doc):
{%- else %}Hello,
{% endif %}
{{ _("Requesting payment against {0} {1} for amount {2}").format(doc.doctype,
- doc.name, doc.get_formatted("grand_total")) }}
+ doc.name, doc.get_formatted("grand_total")) }}
{{ _("Make Payment") }}