chore: refactor by creating is_sold
This commit is contained in:
parent
d4242de699
commit
b734f9d237
@ -660,19 +660,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"
|
||||
@ -690,6 +678,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user