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) <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-06-17 13:19:07 +05:30
parent e69eaa5102
commit 9096b4a9df

View File

@@ -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",