fix(postgres): satisfy strict GROUP BY in Total Stock Summary 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:08 +05:30
parent 9096b4a9df
commit c124e90a89

View File

@@ -4,7 +4,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):
@@ -53,8 +53,9 @@ def get_total_stock(filters):
else:
query = query.select(wh.company).groupby(wh.company)
query = query.select(item.item_code, item.description, Sum(bin.actual_qty).as_("actual_qty")).groupby(
item.item_code
)
# description is constant per grouped item_code -> Max() keeps the GROUP BY valid on postgres
query = query.select(
item.item_code, Max(item.description).as_("description"), Sum(bin.actual_qty).as_("actual_qty")
).groupby(item.item_code)
return query.run()