fix(postgres): satisfy strict GROUP BY in Inactive Customers 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:02 +05:30
parent a3ec98a57c
commit 463103ebf1

View File

@@ -4,8 +4,8 @@
import frappe
from frappe import _
from frappe.query_builder import Case, CustomFunction
from frappe.query_builder.functions import Count, Max, Sum
from frappe.query_builder import Case
from frappe.query_builder.functions import Count, CurDate, DateDiff, Max, Sum
from frappe.utils import cint
@@ -37,9 +37,6 @@ def get_sales_details(doctype):
customer = frappe.qb.DocType("Customer")
sales_doctype = frappe.qb.DocType(doctype)
date_diff = CustomFunction("DATEDIFF", ["d1", "d2"])
current_date = CustomFunction("CURRENT_DATE", [])
if doctype == "Sales Order":
total_considered = Sum(
Case()
@@ -55,7 +52,9 @@ def get_sales_details(doctype):
date_col = sales_doctype.posting_date
last_order_date = Max(date_col)
days_since_last_order = date_diff(current_date(), last_order_date)
# DateDiff is cross-database (DATEDIFF on MariaDB, date subtraction on postgres); CurDate()
# renders the bare CURRENT_DATE keyword. Yields the integer number of days.
days_since_last_order = DateDiff(CurDate(), last_order_date)
return (
frappe.qb.from_(customer)