From d950de2d099509093cf21093290c086e0db03980 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 (cherry picked from commit 0ec30a1ceaac420146e23c72788d05f44778f141) --- 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 55e04a2e262..12d5229c9f3 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -313,7 +313,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"):