fix: asset requiring maintenance sold status
(cherry picked from commit 14ab9d9158)
This commit is contained in:
@@ -643,13 +643,27 @@ 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"
|
||||||
|
|
||||||
if self.journal_entry_for_scrap:
|
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"
|
||||||
|
elif self.journal_entry_for_scrap:
|
||||||
status = "Scrapped"
|
status = "Scrapped"
|
||||||
elif self.finance_books:
|
elif self.finance_books:
|
||||||
idx = self.get_default_finance_book_idx() or 0
|
idx = self.get_default_finance_book_idx() or 0
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import frappe
|
|||||||
from frappe.utils import add_days, add_months, cstr, flt, get_last_day, getdate, nowdate
|
from frappe.utils import add_days, add_months, cstr, flt, get_last_day, getdate, nowdate
|
||||||
|
|
||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||||
from erpnext.assets.doctype.asset.asset import make_sales_invoice
|
from erpnext.assets.doctype.asset.asset import make_sales_invoice, update_maintenance_status
|
||||||
from erpnext.assets.doctype.asset.depreciation import (
|
from erpnext.assets.doctype.asset.depreciation import (
|
||||||
post_depreciation_entries,
|
post_depreciation_entries,
|
||||||
restore_asset,
|
restore_asset,
|
||||||
@@ -238,6 +238,34 @@ class TestAsset(AssetSetup):
|
|||||||
|
|
||||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Partially Depreciated")
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Partially Depreciated")
|
||||||
|
|
||||||
|
def test_asset_with_maintenance_required_status_after_sale(self):
|
||||||
|
asset = create_asset(
|
||||||
|
calculate_depreciation=1,
|
||||||
|
available_for_use_date="2020-06-06",
|
||||||
|
purchase_date="2020-01-01",
|
||||||
|
expected_value_after_useful_life=10000,
|
||||||
|
total_number_of_depreciations=3,
|
||||||
|
frequency_of_depreciation=10,
|
||||||
|
maintenance_required=1,
|
||||||
|
depreciation_start_date="2020-12-31",
|
||||||
|
submit=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
post_depreciation_entries(date="2021-01-01")
|
||||||
|
|
||||||
|
si = make_sales_invoice(asset=asset.name, item_code="Macbook Pro", company="_Test Company")
|
||||||
|
si.customer = "_Test Customer"
|
||||||
|
si.due_date = nowdate()
|
||||||
|
si.get("items")[0].rate = 25000
|
||||||
|
si.insert()
|
||||||
|
si.submit()
|
||||||
|
|
||||||
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
||||||
|
|
||||||
|
update_maintenance_status()
|
||||||
|
|
||||||
|
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
||||||
|
|
||||||
def test_expense_head(self):
|
def test_expense_head(self):
|
||||||
pr = make_purchase_receipt(
|
pr = make_purchase_receipt(
|
||||||
item_code="Macbook Pro", qty=2, rate=200000.0, location="Test Location"
|
item_code="Macbook Pro", qty=2, rate=200000.0, location="Test Location"
|
||||||
@@ -1353,6 +1381,7 @@ def create_asset(**args):
|
|||||||
"number_of_depreciations_booked": args.number_of_depreciations_booked or 0,
|
"number_of_depreciations_booked": args.number_of_depreciations_booked or 0,
|
||||||
"gross_purchase_amount": args.gross_purchase_amount or 100000,
|
"gross_purchase_amount": args.gross_purchase_amount or 100000,
|
||||||
"purchase_receipt_amount": args.purchase_receipt_amount or 100000,
|
"purchase_receipt_amount": args.purchase_receipt_amount or 100000,
|
||||||
|
"maintenance_required": args.maintenance_required or 0,
|
||||||
"warehouse": args.warehouse or "_Test Warehouse - _TC",
|
"warehouse": args.warehouse or "_Test Warehouse - _TC",
|
||||||
"available_for_use_date": args.available_for_use_date or "2020-06-06",
|
"available_for_use_date": args.available_for_use_date or "2020-06-06",
|
||||||
"location": args.location or "Test Location",
|
"location": args.location or "Test Location",
|
||||||
|
|||||||
Reference in New Issue
Block a user