diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index e6f2b2733dd..5737956fe86 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -850,6 +850,7 @@ def update_payment_requests_as_per_pe_references(references=None, cancel=False): ) referenced_payment_requests = {pr.name: pr for pr in referenced_payment_requests} + doc_updates = {} for ref in references: if not ref.payment_request: @@ -875,7 +876,7 @@ def update_payment_requests_as_per_pe_references(references=None, cancel=False): title=_("Invalid Allocated Amount"), ) - # update status + # determine status if new_outstanding_amount == payment_request["grand_total"]: status = "Initiated" if payment_request["payment_request_type"] == "Outward" else "Requested" elif new_outstanding_amount == 0: @@ -883,12 +884,15 @@ def update_payment_requests_as_per_pe_references(references=None, cancel=False): elif new_outstanding_amount > 0: status = "Partially Paid" - # update database - frappe.db.set_value( - "Payment Request", - ref.payment_request, - {"outstanding_amount": new_outstanding_amount, "status": status}, - ) + # prepare bulk update data + doc_updates[ref.payment_request] = { + "outstanding_amount": new_outstanding_amount, + "status": status, + } + + # bulk update all payment requests + if doc_updates: + frappe.db.bulk_update("Payment Request", doc_updates) def get_dummy_message(doc):