fix: consider the existing paid payment request for phone payment channel
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index cb58f89..1b97050 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -393,6 +393,10 @@
frappe.throw(_("Payment Entry is already created"))
def get_existing_payment_request_amount(ref_dt, ref_dn):
+ """
+ Get the existing payment request which are unpaid or partially paid for payment channel other than Phone
+ and get the summation of existing paid payment request for Phone payment channel.
+ """
existing_payment_request_amount = frappe.db.sql("""
select sum(grand_total)
from `tabPayment Request`
@@ -400,7 +404,9 @@
reference_doctype = %s
and reference_name = %s
and docstatus = 1
- and status = 'Paid'
+ and (status != 'Paid'
+ or (payment_channel = 'Phone'
+ and status = 'Paid'))
""", (ref_dt, ref_dn))
return flt(existing_payment_request_amount[0][0]) if existing_payment_request_amount else 0
diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py
index 747bad8..8a10e2c 100644
--- a/erpnext/accounts/doctype/payment_request/test_payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py
@@ -127,7 +127,6 @@
recipient_id="nabin@erpnext.com", return_doc=1)
pr1.grand_total = 200
pr1.submit()
- pr1.set_as_paid()
# Make a 2nd Payment Request
pr2 = make_payment_request(dt="Sales Order", dn=so.name,