From 813dcca29aadecb77e6bc31eacf0469f147a5f5a Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 1 Jul 2026 09:10:18 +0530 Subject: [PATCH] fix(accounts): tie-break open Payment Request ordering for cross-engine parity get_open_payment_requests_for_references orders by Coalesce(transaction_date, creation); when transaction_date is set the coalesce never falls back to creation, so PRs sharing a transaction_date have no tiebreaker and MariaDB/Postgres can allocate a different PR first. Append creation, name keys. Co-Authored-By: Claude Opus 4.8 --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index b4005436ec0..706644c9819 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -2795,6 +2795,9 @@ def get_open_payment_requests_for_references(references=None): .where(PR.docstatus == 1) .where(PR.outstanding_amount > 0) # to avoid old PRs with 0 outstanding amount .orderby(Coalesce(PR.transaction_date, PR.creation), order=frappe.qb.asc) + # unique tiebreaker so PRs sharing a transaction_date allocate in the same order on both engines + .orderby(PR.creation, order=frappe.qb.asc) + .orderby(PR.name, order=frappe.qb.asc) ).run(as_dict=True) if not response: