From 9096b4a9df263ffe181f9934fe4c06b12ca571e6 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 17 Jun 2026 13:19:07 +0530 Subject: [PATCH] fix(postgres): satisfy strict GROUP BY in Stock And Account Value Comparison 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) --- .../stock_and_account_value_comparison.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py index d3654606613..48ca58cd334 100644 --- a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py +++ b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py @@ -86,12 +86,14 @@ def get_stock_ledger_data(report_filters, filters): "Stock Ledger Entry", filters=filters, fields=[ - "name", + # name is arbitrary per grouped voucher (many SLEs); posting_date/posting_time are constant + # per voucher -> MAX() keeps the GROUP BY valid on postgres with the same values MySQL picked. + {"MAX": "name", "as": "name"}, "voucher_type", "voucher_no", {"SUM": "stock_value_difference", "as": "stock_value"}, - "posting_date", - "posting_time", + {"MAX": "posting_date", "as": "posting_date"}, + {"MAX": "posting_time", "as": "posting_time"}, ], group_by="voucher_type, voucher_no", order_by="posting_date ASC, posting_time ASC", @@ -113,10 +115,12 @@ def get_gl_data(report_filters, filters): "GL Entry", filters=filters, fields=[ - "name", + # name is arbitrary per grouped voucher (many GL entries); posting_date is constant per + # voucher -> MAX() keeps the GROUP BY valid on postgres with the same values MySQL picked. + {"MAX": "name", "as": "name"}, "voucher_type", "voucher_no", - "posting_date", + {"MAX": "posting_date", "as": "posting_date"}, { "SUB": [{"SUM": "debit_in_account_currency"}, {"SUM": "credit_in_account_currency"}], "as": "account_value",