From 43b85c571101d3d8d5d2f5a9f041ba176ceb243e Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Tue, 1 Aug 2023 11:47:48 +0530 Subject: [PATCH] fix: allow fully depreciated existing assets (#36378) --- erpnext/assets/doctype/asset/asset.json | 21 +++++++++++++------- erpnext/assets/doctype/asset/asset.py | 13 ++++++++---- erpnext/assets/doctype/asset/depreciation.py | 9 +++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index 3e93f0f03e3..78cbe8621fa 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -43,6 +43,7 @@ "column_break_33", "opening_accumulated_depreciation", "number_of_depreciations_booked", + "is_fully_depreciated", "section_break_36", "finance_books", "section_break_33", @@ -205,6 +206,7 @@ "fieldname": "disposal_date", "fieldtype": "Date", "label": "Disposal Date", + "no_copy": 1, "read_only": 1 }, { @@ -244,19 +246,17 @@ "label": "Is Existing Asset" }, { - "depends_on": "is_existing_asset", + "depends_on": "eval:(doc.is_existing_asset)", "fieldname": "opening_accumulated_depreciation", "fieldtype": "Currency", "label": "Opening Accumulated Depreciation", - "no_copy": 1, "options": "Company:company:default_currency" }, { - "depends_on": "eval:(doc.is_existing_asset && doc.opening_accumulated_depreciation)", + "depends_on": "eval:(doc.is_existing_asset)", "fieldname": "number_of_depreciations_booked", "fieldtype": "Int", - "label": "Number of Depreciations Booked", - "no_copy": 1 + "label": "Number of Depreciations Booked" }, { "collapsible": 1, @@ -502,6 +502,13 @@ "options": "\nSuccessful\nFailed", "print_hide": 1, "read_only": 1 + }, + { + "default": "0", + "depends_on": "eval:(doc.is_existing_asset)", + "fieldname": "is_fully_depreciated", + "fieldtype": "Check", + "label": "Is Fully Depreciated" } ], "idx": 72, @@ -530,7 +537,7 @@ "table_fieldname": "accounts" } ], - "modified": "2023-03-30 15:07:41.542374", + "modified": "2023-07-28 15:47:01.137996", "modified_by": "Administrator", "module": "Assets", "name": "Asset", @@ -574,4 +581,4 @@ "states": [], "title_field": "asset_name", "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index c6247ea0da3..b8d8ba5b486 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -207,8 +207,11 @@ class Asset(AccountsController): if not self.calculate_depreciation: return - elif not self.finance_books: - frappe.throw(_("Enter depreciation details")) + else: + if not self.finance_books: + frappe.throw(_("Enter depreciation details")) + if self.is_fully_depreciated: + frappe.throw(_("Depreciation cannot be calculated for fully depreciated assets")) if self.is_existing_asset: return @@ -588,7 +591,7 @@ class Asset(AccountsController): depreciable_amount = flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life) if flt(self.opening_accumulated_depreciation) > depreciable_amount: frappe.throw( - _("Opening Accumulated Depreciation must be less than equal to {0}").format( + _("Opening Accumulated Depreciation must be less than or equal to {0}").format( depreciable_amount ) ) @@ -793,7 +796,9 @@ class Asset(AccountsController): expected_value_after_useful_life = self.finance_books[idx].expected_value_after_useful_life value_after_depreciation = self.finance_books[idx].value_after_depreciation - if flt(value_after_depreciation) <= expected_value_after_useful_life: + if ( + flt(value_after_depreciation) <= expected_value_after_useful_life or self.is_fully_depreciated + ): status = "Fully Depreciated" elif flt(value_after_depreciation) < flt(self.gross_purchase_amount): status = "Partially Depreciated" diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index d72c4bd654b..80262c04d4a 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -369,6 +369,15 @@ def reverse_depreciation_entry_made_after_disposal(asset, date): reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry) reverse_journal_entry.posting_date = nowdate() + + for account in reverse_journal_entry.accounts: + account.update( + { + "reference_type": "Asset", + "reference_name": asset.name, + } + ) + frappe.flags.is_reverse_depr_entry = True reverse_journal_entry.submit()