chore: refactor by creating is_sold
(cherry picked from commit 430a4c98a0)
This commit is contained in:
@@ -649,19 +649,7 @@ class Asset(AccountsController):
|
||||
elif self.docstatus == 1:
|
||||
status = "Submitted"
|
||||
|
||||
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:
|
||||
if self.is_sold():
|
||||
status = "Sold"
|
||||
elif self.journal_entry_for_scrap:
|
||||
status = "Scrapped"
|
||||
@@ -679,6 +667,21 @@ class Asset(AccountsController):
|
||||
status = "Cancelled"
|
||||
return status
|
||||
|
||||
def is_sold(self):
|
||||
item = frappe.qb.DocType("Sales Invoice Item").as_("item")
|
||||
si = frappe.qb.DocType("Sales Invoice").as_("si")
|
||||
|
||||
asset_sales_invoice = (
|
||||
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()
|
||||
|
||||
return True if asset_sales_invoice else False
|
||||
|
||||
def get_default_finance_book_idx(self):
|
||||
if not self.get("default_finance_book") and self.company:
|
||||
self.default_finance_book = erpnext.get_default_finance_book(self.company)
|
||||
|
||||
Reference in New Issue
Block a user