From 23778c3875e04cfeaf5f57abf2b289ab174a2906 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 17 Jun 2026 13:18:57 +0530 Subject: [PATCH] fix(postgres): satisfy strict GROUP BY in Voucher Wise Balance report Wrap the non-aggregated, functionally-dependent column(s) in Max()/Min() (or add them to GROUP BY) so the report's grouped query is valid under PostgreSQL's strict GROUP BY. No behaviour change on MariaDB. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../voucher_wise_balance/voucher_wise_balance.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py b/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py index 1918165c6db..e02a898d40d 100644 --- a/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py +++ b/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py @@ -3,7 +3,7 @@ import frappe from frappe import _ -from frappe.query_builder.functions import Sum +from frappe.query_builder.functions import Max, Sum def execute(filters=None): @@ -43,7 +43,13 @@ def get_data(filters): gle = frappe.qb.DocType("GL Entry") query = ( frappe.qb.from_(gle) - .select(gle.voucher_type, gle.voucher_no, Sum(gle.debit).as_("debit"), Sum(gle.credit).as_("credit")) + # voucher_type is constant per grouped voucher_no -> Max() keeps the GROUP BY valid on postgres + .select( + Max(gle.voucher_type).as_("voucher_type"), + gle.voucher_no, + Sum(gle.debit).as_("debit"), + Sum(gle.credit).as_("credit"), + ) .where(gle.is_cancelled == 0) .groupby(gle.voucher_no) )