mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-12 06:01:46 +00:00
Merge pull request #56681 from mihir-kandoi/pg-b4-orderby-tiebreakers
fix: add unique tiebreakers to ORDER BY … LIMIT 1 picks for MariaDB↔Postgres parity
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user