chore: rewrite query using frappe.qb
This commit is contained in:
parent
0618f606b2
commit
f4bf9c672f
@ -654,20 +654,23 @@ class Asset(AccountsController):
|
||||
self.db_set("status", status)
|
||||
|
||||
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:
|
||||
status = "Draft"
|
||||
elif self.docstatus == 1:
|
||||
status = "Submitted"
|
||||
|
||||
is_asset_sold = frappe.db.sql(
|
||||
"""
|
||||
select item.parent
|
||||
from `tabSales Invoice Item` item, `tabSales Invoice` p
|
||||
where item.asset=%s and item.parent = p.name and p.docstatus = 1
|
||||
""",
|
||||
self.name,
|
||||
)
|
||||
item = frappe.qb.DocType("Sales Invoice Item").as_("item")
|
||||
si = frappe.qb.DocType("Sales Invoice").as_("si")
|
||||
|
||||
is_asset_sold = (
|
||||
frappe.qb.from_(item)
|
||||
.select(item.parent)
|
||||
.inner_join(si)
|
||||
.on(item.parent == si.name)
|
||||
.where(item.asset == self.name)
|
||||
.where(si.docstatus == 1)
|
||||
).run()
|
||||
|
||||
if is_asset_sold:
|
||||
status = "Sold"
|
||||
|
Loading…
x
Reference in New Issue
Block a user