chore: rewrite query using frappe.qb

This commit is contained in:
anandbaburajan 2022-09-28 18:20:20 +05:30
parent 0618f606b2
commit f4bf9c672f

View File

@ -654,20 +654,23 @@ class Asset(AccountsController):
self.db_set("status", status) self.db_set("status", status)
def get_status(self): def get_status(self):
"""Returns status based on whether it is draft, submitted, scrapped or depreciated""" """Returns status based on whether it is draft, submitted, sold, scrapped or depreciated"""
if self.docstatus == 0: if self.docstatus == 0:
status = "Draft" status = "Draft"
elif self.docstatus == 1: elif self.docstatus == 1:
status = "Submitted" status = "Submitted"
is_asset_sold = frappe.db.sql( item = frappe.qb.DocType("Sales Invoice Item").as_("item")
""" si = frappe.qb.DocType("Sales Invoice").as_("si")
select item.parent
from `tabSales Invoice Item` item, `tabSales Invoice` p is_asset_sold = (
where item.asset=%s and item.parent = p.name and p.docstatus = 1 frappe.qb.from_(item)
""", .select(item.parent)
self.name, .inner_join(si)
) .on(item.parent == si.name)
.where(item.asset == self.name)
.where(si.docstatus == 1)
).run()
if is_asset_sold: if is_asset_sold:
status = "Sold" status = "Sold"