mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-04 00:50:18 +00:00
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:
@@ -1269,6 +1269,10 @@ def get_item_price(
|
|||||||
& (IfNull(ip.valid_upto, "2500-12-31") >= pctx.transaction_date)
|
& (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)
|
return query.run(as_dict=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user