refactor(postgres): port Cashier Closing doctype queries to the query builder

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-06-17 18:38:00 +05:30
parent c0d2bd7bce
commit ac26c01e52

View File

@@ -5,6 +5,7 @@
import frappe import frappe
from frappe import _ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.query_builder.functions import Sum
from frappe.utils import flt from frappe.utils import flt
@@ -43,13 +44,17 @@ class CashierClosing(Document):
self.make_calculations() self.make_calculations()
def get_outstanding(self): def get_outstanding(self):
values = frappe.db.sql( si = frappe.qb.DocType("Sales Invoice")
""" values = (
select sum(outstanding_amount) frappe.qb.from_(si)
from `tabSales Invoice` .select(Sum(si.outstanding_amount))
where posting_date=%s and posting_time>=%s and posting_time<=%s and owner=%s .where(
""", (si.posting_date == self.date)
(self.date, self.from_time, self.time, self.user), & (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) self.outstanding_amount = flt(values[0][0] if values else 0)