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)