From 3e9c4aefafc196bbd643a2821ef02bbaeffab7bc Mon Sep 17 00:00:00 2001 From: Loic Oberle Date: Fri, 29 May 2026 10:00:45 +0200 Subject: [PATCH] refactor(sales_invoice): replace sql with qb in validate_proj_cust (#55382) --- .../doctype/sales_invoice/sales_invoice.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index db2a2e1fe41..2589ce8ee91 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1134,12 +1134,20 @@ class SalesInvoice(SellingController): def validate_proj_cust(self): """check for does customer belong to same project as entered..""" if self.project and self.customer: - res = frappe.db.sql( - """select name from `tabProject` - where name = %s and (customer = %s or customer is null or customer = '')""", - (self.project, self.customer), + Project = frappe.qb.DocType("Project") + + query = ( + frappe.qb.from_(Project) + .select(Project.name) + .where(Project.name == self.project) + .where( + (Project.customer == self.customer) + | (Project.customer.isnull()) + | (Project.customer == "") + ) ) - if not res: + + if not query.run(): throw(_("Customer {0} does not belong to project {1}").format(self.customer, self.project)) def validate_pos(self):