fix(accounts): break last-purchase-rate ties deterministically in Gross Profit

get_last_purchase_rate ordered by posting_date DESC only; same-date Purchase Invoices yielded an undefined last_purchase_rate that diverged between MariaDB and Postgres. Add purchase_invoice.name DESC tiebreaker.
This commit is contained in:
Mihir Kandoi
2026-06-29 16:29:45 +05:30
parent 93c186fea7
commit e52b9825e3

View File

@@ -895,7 +895,11 @@ class GrossProfitGenerator:
if row.cost_center:
query = query.where(purchase_invoice_item.cost_center == row.cost_center)
query = query.orderby(purchase_invoice.posting_date, order=frappe.qb.desc).limit(1)
query = (
query.orderby(purchase_invoice.posting_date, order=frappe.qb.desc)
.orderby(purchase_invoice.name, order=frappe.qb.desc)
.limit(1)
)
last_purchase_rate = query.run()
return flt(last_purchase_rate[0][0]) if last_purchase_rate else 0