From 5e66231ca4e8dc93659f229843fd632181408ca9 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Thu, 20 Feb 2025 15:03:19 +0530 Subject: [PATCH] perf: replace if function in query --- erpnext/projects/doctype/project/project.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 5706edcda63..417c73ec685 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -325,10 +325,10 @@ class Project(Document): # nosemgrep total_billed_amount = frappe.db.sql( """select sum(base_net_amount) - from `tabSales Invoice Item` si_item, `tabSales Invoice` si - where si_item.parent = si.name - and if(si_item.project, si_item.project, si.project) = %s - and si.docstatus=1""", + from `tabSales Invoice Item` si_item + join `tabSales Invoice` si on si_item.parent = si.name + where (si_item.project = %s or (si_item.project is null and si.project = %s)) + and si.docstatus = 1""", self.name, )