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) <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-06-17 13:18:57 +05:30
parent 24a66d10e7
commit 23778c3875

View File

@@ -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)
)