From 463103ebf131ad150ce6446a6cff20529884c25b Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 17 Jun 2026 13:19:02 +0530 Subject: [PATCH] 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) --- .../report/inactive_customers/inactive_customers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/report/inactive_customers/inactive_customers.py b/erpnext/selling/report/inactive_customers/inactive_customers.py index 8c7c7b99a32..2dedb346601 100644 --- a/erpnext/selling/report/inactive_customers/inactive_customers.py +++ b/erpnext/selling/report/inactive_customers/inactive_customers.py @@ -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)