From ac26c01e52f575b1fd3eae78b9ecc16f5e2411ef Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 17 Jun 2026 18:38:00 +0530 Subject: [PATCH] refactor(postgres): port Cashier Closing doctype queries to the query builder Co-Authored-By: Claude Opus 4.8 (1M context) --- .../cashier_closing/cashier_closing.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/cashier_closing/cashier_closing.py b/erpnext/accounts/doctype/cashier_closing/cashier_closing.py index 6ab94c5c51b..e89f2830223 100644 --- a/erpnext/accounts/doctype/cashier_closing/cashier_closing.py +++ b/erpnext/accounts/doctype/cashier_closing/cashier_closing.py @@ -5,6 +5,7 @@ import frappe from frappe import _ from frappe.model.document import Document +from frappe.query_builder.functions import Sum from frappe.utils import flt @@ -43,13 +44,17 @@ class CashierClosing(Document): self.make_calculations() def get_outstanding(self): - values = frappe.db.sql( - """ - select sum(outstanding_amount) - from `tabSales Invoice` - where posting_date=%s and posting_time>=%s and posting_time<=%s and owner=%s - """, - (self.date, self.from_time, self.time, self.user), + si = frappe.qb.DocType("Sales Invoice") + values = ( + frappe.qb.from_(si) + .select(Sum(si.outstanding_amount)) + .where( + (si.posting_date == self.date) + & (si.posting_time >= self.from_time) + & (si.posting_time <= self.time) + & (si.owner == self.user) + ) + .run() ) self.outstanding_amount = flt(values[0][0] if values else 0)