mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-15 15:38:39 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user