From 8939e95c625676b65d18d0a93a435ec04d654547 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 22 Jun 2023 23:01:59 +0530 Subject: [PATCH] chore: asset scrap and restore fixes [v14] (backport #35851) (#35854) * chore: asset scrap and restore fixes [v14] (#35851) chore: better err msg on cancelling JE for asset scrap and allow restoring non-depr assets (cherry picked from commit 69780da0996d00a6e8fc81b2fce860e47f971b30) # Conflicts: # erpnext/assets/doctype/asset/depreciation.py * chore: fix conflict --------- Co-authored-by: Anand Baburajan --- .../doctype/journal_entry/journal_entry.py | 15 +++++++++++---- erpnext/assets/doctype/asset/depreciation.py | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index f988222c6c22..f468a35c2467 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -330,12 +330,10 @@ def unlink_advance_entry_reference(self): d.db_update() def unlink_asset_reference(self): - if self.voucher_type != "Depreciation Entry": - return - for d in self.get("accounts"): if ( - d.reference_type == "Asset" + self.voucher_type == "Depreciation Entry" + and d.reference_type == "Asset" and d.reference_name and d.account_type == "Depreciation" and d.debit @@ -362,6 +360,15 @@ def unlink_asset_reference(self): else: asset.db_set("value_after_depreciation", asset.value_after_depreciation + d.debit) asset.set_status() + elif self.voucher_type == "Journal Entry" and d.reference_type == "Asset" and d.reference_name: + journal_entry_for_scrap = frappe.db.get_value( + "Asset", d.reference_name, "journal_entry_for_scrap" + ) + + if journal_entry_for_scrap == self.name: + frappe.throw( + _("Journal Entry for Asset scrapping cannot be cancelled. Please restore the Asset.") + ) def unlink_inter_company_jv(self): if ( diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py index e54319930a58..aa9cc38be22c 100644 --- a/erpnext/assets/doctype/asset/depreciation.py +++ b/erpnext/assets/doctype/asset/depreciation.py @@ -344,6 +344,9 @@ def modify_depreciation_schedule_for_asset_repairs(asset): def reverse_depreciation_entry_made_after_disposal(asset, date): from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry + if not asset.calculate_depreciation: + return + row = -1 finance_book = asset.get("schedules")[0].get("finance_book") for schedule in asset.get("schedules"):