From 63ea907881b7dfbe7f36dc3da8bf2055061ccb20 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Mon, 29 Jun 2026 16:29:43 +0530 Subject: [PATCH] fix(accounts): break exchange-rate revaluation GLE ties deterministically calculate_exchange_rate_using_last_gle ordered the latest-GLE lookups by posting_date DESC only. With multiple GL Entries on the latest posting_date the picked row was undefined, so MariaDB and Postgres could choose different vouchers and return a different last_exchange_rate (and revaluation gain/loss). Add gl.name DESC as a tiebreaker so both engines pick the same row; MariaDB row count unchanged. --- .../exchange_rate_revaluation/exchange_rate_revaluation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py index 4213d478ce1..0ed30eaee52 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py @@ -601,6 +601,7 @@ def calculate_exchange_rate_using_last_gle(company, account, party_type, party): .select(gl.voucher_type, gl.voucher_no) .where(Criterion.all(conditions)) .orderby(gl.posting_date, order=Order.desc) + .orderby(gl.name, order=Order.desc) .limit(1) .run()[0] ) @@ -615,6 +616,7 @@ def calculate_exchange_rate_using_last_gle(company, account, party_type, party): (gl.voucher_type == voucher_type) & (gl.voucher_no == voucher_no) & (gl.account == account) ) .orderby(gl.posting_date, order=Order.desc) + .orderby(gl.name, order=Order.desc) .limit(1) .run()[0][0] )