From 0998123e5216ff389ddb57216aa4d5c40941f754 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Mon, 8 Dec 2025 18:00:29 +0530 Subject: [PATCH] refactor: payment request status updates with bulk database operation (cherry picked from commit 5154fa8259ad152260367634d11ea0940c2b6b53) --- .../doctype/payment_request/payment_request.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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):