fix(stock): pin get_item_price tie-break so MariaDB and Postgres agree

get_item_price ORDER BYs valid_from/batch_no/uom/party then LIMIT 1 with no unique key. Two Item
Price rows tied on all of those but differing price_list_rate would be picked arbitrarily -- MariaDB
and Postgres can return a different rate. Append a name tiebreaker; for exact ties MariaDB's pick was
already undefined, so its output is preserved.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-07-01 09:10:16 +05:30
parent 85853fce12
commit 7f6a234cf7

View File

@@ -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)