From f846c55c01813c8da4aae0232b5a94754402853b Mon Sep 17 00:00:00 2001 From: Loic Oberle Date: Fri, 29 May 2026 09:59:10 +0200 Subject: [PATCH] refactor(sales_invoice): replace sql with qb in get_warehouse (#55381) --- .../doctype/sales_invoice/sales_invoice.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index fbd5d377a08..db2a2e1fe41 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1364,19 +1364,28 @@ class SalesInvoice(SellingController): self.total_billing_hours = timesheet_sum("billing_hours") def get_warehouse(self): - user_pos_profile = frappe.db.sql( - """select name, warehouse from `tabPOS Profile` - where ifnull(user,'') = %s and company = %s""", - (frappe.session["user"], self.company), + POSProfile = frappe.qb.DocType("POS Profile") + + user_query = ( + frappe.qb.from_(POSProfile) + .select(POSProfile.name, POSProfile.warehouse) + .where(POSProfile.company == self.company) + .where( + (POSProfile.user == frappe.session["user"]) + | ((POSProfile.user.isnull() | (POSProfile.user == "")) & (frappe.session["user"] == "")) + ) ) + user_pos_profile = user_query.run() warehouse = user_pos_profile[0][1] if user_pos_profile else None if not warehouse: - global_pos_profile = frappe.db.sql( - """select name, warehouse from `tabPOS Profile` - where (user is null or user = '') and company = %s""", - self.company, + global_query = ( + frappe.qb.from_(POSProfile) + .select(POSProfile.name, POSProfile.warehouse) + .where(POSProfile.company == self.company) + .where(POSProfile.user.isnull() | (POSProfile.user == "")) ) + global_pos_profile = global_query.run() if global_pos_profile: warehouse = global_pos_profile[0][1]