From 0ec30a1ceaac420146e23c72788d05f44778f141 Mon Sep 17 00:00:00 2001 From: Fawaz Alhafiz <48890670+fawaaaz111@users.noreply.github.com> Date: Thu, 2 Oct 2025 14:24:51 +0300 Subject: [PATCH] fix: SQL operator precedence in Project query customer filter Added explicit parentheses around customer OR conditions in get_project_name() to ensure proper grouping with AND filters. Without these parentheses, SQL operator precedence caused the status filter to be bypassed when a customer filter was applied, resulting in completed and cancelled projects appearing in link field dropdowns. Before: WHERE customer='X' OR customer IS NULL OR customer='' AND status NOT IN (...) was interpreted as: WHERE customer='X' OR customer IS NULL OR (customer='' AND status NOT IN (...)) After: WHERE (customer='X' OR customer IS NULL OR customer='') AND status NOT IN (...) Fixes: Completed/cancelled projects showing in Project link fields Affected: Any doctype using Project link fields with customer filters --- erpnext/controllers/queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index a77e338ff32..aae0fd4e9e5 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -318,7 +318,7 @@ def get_project_name(doctype, txt, searchfield, start, page_len, filters): if filters: if filters.get("customer"): qb_filter_and_conditions.append( - (proj.customer == filters.get("customer")) | proj.customer.isnull() | proj.customer == "" + (proj.customer == filters.get("customer")) | (proj.customer.isnull()) | (proj.customer == "") ) if filters.get("company"):