From 0d5abf1c9522e70928981b0ad310ce7b75bc027f Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Tue, 21 Mar 2023 14:30:28 +0530 Subject: [PATCH] refactor: calc depr in asset repair and if statement (#34526) refactor: minor asset repair of calc depr and if statement --- erpnext/assets/doctype/asset/asset.py | 27 ++++++++++--------- .../doctype/asset_repair/asset_repair.py | 16 +++-------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 181309de951..e46cdb9fc64 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -380,21 +380,24 @@ class Asset(AccountsController): value_after_depreciation -= flt(depreciation_amount, self.precision("gross_purchase_amount")) # Adjust depreciation amount in the last period based on the expected value after useful life - if finance_book.expected_value_after_useful_life and ( - ( - n == cint(number_of_pending_depreciations) - 1 - and value_after_depreciation != finance_book.expected_value_after_useful_life + if ( + finance_book.expected_value_after_useful_life + and ( + ( + n == cint(number_of_pending_depreciations) - 1 + and value_after_depreciation != finance_book.expected_value_after_useful_life + ) + or value_after_depreciation < finance_book.expected_value_after_useful_life ) - or value_after_depreciation < finance_book.expected_value_after_useful_life - ): - if ( + and ( not self.flags.increase_in_asset_value_due_to_repair or not finance_book.depreciation_method in ("Written Down Value", "Double Declining Balance") - ): - depreciation_amount += ( - value_after_depreciation - finance_book.expected_value_after_useful_life - ) - skip_row = True + ) + ): + depreciation_amount += ( + value_after_depreciation - finance_book.expected_value_after_useful_life + ) + skip_row = True if depreciation_amount > 0: self.append( diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 222e30134ce..edcbf3e2fd0 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -50,19 +50,15 @@ class AssetRepair(AccountsController): self.check_for_stock_items_and_warehouse() self.decrease_stock_quantity() - calculate_asset_depreciation = frappe.db.get_value( - "Asset", self.asset, "calculate_depreciation" - ) - if self.get("capitalize_repair_cost"): self.make_gl_entries() - if calculate_asset_depreciation and self.increase_in_asset_life: + if self.asset_doc.calculate_depreciation and self.increase_in_asset_life: self.modify_depreciation_schedule() self.asset_doc.flags.ignore_validate_update_after_submit = True self.asset_doc.prepare_depreciation_data() - if calculate_asset_depreciation: + if self.asset_doc.calculate_depreciation: self.update_asset_expected_value_after_useful_life() self.asset_doc.save() @@ -79,20 +75,16 @@ class AssetRepair(AccountsController): if self.get("stock_consumption"): self.increase_stock_quantity() - calculate_asset_depreciation = frappe.db.get_value( - "Asset", self.asset, "calculate_depreciation" - ) - if self.get("capitalize_repair_cost"): self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry") self.make_gl_entries(cancel=True) - if calculate_asset_depreciation and self.increase_in_asset_life: + if self.asset_doc.calculate_depreciation and self.increase_in_asset_life: self.revert_depreciation_schedule_on_cancellation() self.asset_doc.flags.ignore_validate_update_after_submit = True self.asset_doc.prepare_depreciation_data() - if calculate_asset_depreciation: + if self.asset_doc.calculate_depreciation: self.update_asset_expected_value_after_useful_life() self.asset_doc.save()