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: diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index 8f0bc136458..bd96ae38cc9 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -464,6 +464,9 @@ def set_customer_info(fieldname: str, customer: str, value: str = ""): & (DynamicLink.link_doctype == "Customer") ) .orderby(Contact.is_primary_contact, order=Order.desc) + # tiebreaker: contacts tie on is_primary_contact (the common no-primary case) -> + # pick the same one on MariaDB and Postgres + .orderby(DynamicLink.parent, order=Order.asc) ) contacts = query.run(pluck=DynamicLink.parent) diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index 5aff12994c9..9ec908c6b62 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -326,7 +326,8 @@ def update_packed_item_with_pick_list_info(main_item_row, pi_row): }, ["warehouse", "batch_no", "serial_no"], as_dict=True, - order_by="qty desc", + # name tiebreaker: split pick-list rows can tie on qty -> pick the same warehouse/batch/serial on both engines + order_by="qty desc, name asc", ) if not pl_row: diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 33aceab0bf3..aa9750f7523 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1269,6 +1269,10 @@ def get_item_price( & (IfNull(ip.valid_upto, "2500-12-31") >= pctx.transaction_date) ) + # Final unique tiebreaker: rows tied on every sort key above (same valid_from/batch/uom/party) + # would otherwise be picked arbitrarily -- MariaDB and Postgres can differ. Pin the pick. + query = query.orderby(ip.name, order=frappe.qb.desc) + return query.run(as_dict=True)