From 1f70dd6e9865604d9f16b91cddcf989729898ccb Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 14 Oct 2021 16:23:12 +0530 Subject: [PATCH] fix: value_after_depreciation calculation (#27954) --- erpnext/assets/doctype/asset/asset.py | 2 +- erpnext/assets/doctype/asset/test_asset.py | 21 +++++++++++++++++++ .../doctype/asset_repair/test_asset_repair.py | 10 ++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 7e135be30b..99a6cc35db 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -194,7 +194,7 @@ class Asset(AccountsController): start = self.clear_depreciation_schedule() # value_after_depreciation - current Asset value - if d.value_after_depreciation: + if self.docstatus == 1 and d.value_after_depreciation: value_after_depreciation = (flt(d.value_after_depreciation) - flt(self.opening_accumulated_depreciation)) else: diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 7183ee7e36..cf4581b4a1 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -682,6 +682,27 @@ class TestAsset(unittest.TestCase): # reset indian company frappe.flags.company = company_flag + def test_expected_value_change(self): + """ + tests if changing `expected_value_after_useful_life` + affects `value_after_depreciation` + """ + + asset = create_asset(calculate_depreciation=1) + asset.opening_accumulated_depreciation = 2000 + asset.number_of_depreciations_booked = 1 + + asset.finance_books[0].expected_value_after_useful_life = 100 + asset.save() + asset.reload() + self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0) + + # changing expected_value_after_useful_life shouldn't affect value_after_depreciation + asset.finance_books[0].expected_value_after_useful_life = 200 + asset.save() + asset.reload() + self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0) + def create_asset_data(): if not frappe.db.exists("Asset Category", "Computers"): create_asset_category() diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 9945a328cf..30e3a5296e 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -22,7 +22,7 @@ class TestAssetRepair(unittest.TestCase): frappe.db.sql("delete from `tabTax Rule`") def test_update_status(self): - asset = create_asset() + asset = create_asset(submit=1) initial_status = asset.status asset_repair = create_asset_repair(asset = asset) @@ -76,7 +76,7 @@ class TestAssetRepair(unittest.TestCase): self.assertEqual(stock_entry.items[0].qty, asset_repair.stock_items[0].consumed_quantity) def test_increase_in_asset_value_due_to_stock_consumption(self): - asset = create_asset(calculate_depreciation = 1) + asset = create_asset(calculate_depreciation = 1, submit=1) initial_asset_value = get_asset_value(asset) asset_repair = create_asset_repair(asset= asset, stock_consumption = 1, submit = 1) asset.reload() @@ -85,7 +85,7 @@ class TestAssetRepair(unittest.TestCase): self.assertEqual(asset_repair.stock_items[0].total_value, increase_in_asset_value) def test_increase_in_asset_value_due_to_repair_cost_capitalisation(self): - asset = create_asset(calculate_depreciation = 1) + asset = create_asset(calculate_depreciation = 1, submit=1) initial_asset_value = get_asset_value(asset) asset_repair = create_asset_repair(asset= asset, capitalize_repair_cost = 1, submit = 1) asset.reload() @@ -103,7 +103,7 @@ class TestAssetRepair(unittest.TestCase): self.assertEqual(asset_repair.name, gl_entry.voucher_no) def test_increase_in_asset_life(self): - asset = create_asset(calculate_depreciation = 1) + asset = create_asset(calculate_depreciation = 1, submit=1) initial_num_of_depreciations = num_of_depreciations(asset) create_asset_repair(asset= asset, capitalize_repair_cost = 1, submit = 1) asset.reload() @@ -126,7 +126,7 @@ def create_asset_repair(**args): if args.asset: asset = args.asset else: - asset = create_asset(is_existing_asset = 1) + asset = create_asset(is_existing_asset = 1, submit=1) asset_repair = frappe.new_doc("Asset Repair") asset_repair.update({ "asset": asset.name,