From a7c1ebacbe722e2a2c6acfd90369501373ef4db9 Mon Sep 17 00:00:00 2001 From: Mohd Haris Date: Fri, 26 Jun 2026 17:34:49 +0530 Subject: [PATCH] fix(asset): conditionally show Is Fully Depreciated field The "Is Fully Depreciated" field was hidden on the Asset form (hidden: 1), so it could never be set for manually entered existing assets. Make it visible based on context: - Existing Asset with Calculate Depreciation off -> visible and editable - Calculate Depreciation on -> visible but read-only and forced unchecked (it is only meaningful for manually entered assets) The unchecked value is enforced in the form script (immediate feedback on toggle and on load) and in server-side validate() so it can never be saved as checked while depreciation is being calculated. Co-Authored-By: Claude Opus 4.8 --- erpnext/assets/doctype/asset/asset.js | 9 +++++++++ erpnext/assets/doctype/asset/asset.json | 5 +++-- erpnext/assets/doctype/asset/asset.py | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index e269f289307..8e8f133b109 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -93,6 +93,11 @@ frappe.ui.form.on("Asset", { frappe.ui.form.trigger("Asset", "asset_type"); frm.toggle_display("next_depreciation_date", frm.doc.docstatus < 1); + if (frm.doc.docstatus < 1 && frm.doc.calculate_depreciation && frm.doc.is_fully_depreciated) { + // Is Fully Depreciated is read-only while depreciation is calculated, so keep it unchecked + frm.set_value("is_fully_depreciated", 0); + } + let has_create_buttons = false; if (frm.doc.docstatus == 1) { if (["Submitted", "Partially Depreciated"].includes(frm.doc.status)) { @@ -727,6 +732,10 @@ frappe.ui.form.on("Asset", { calculate_depreciation: function (frm) { frm.toggle_reqd("finance_books", frm.doc.calculate_depreciation); + if (frm.doc.calculate_depreciation && frm.doc.is_fully_depreciated) { + // Is Fully Depreciated is read-only while depreciation is calculated, so keep it unchecked + frm.set_value("is_fully_depreciated", 0); + } if (frm.doc.item_code && frm.doc.calculate_depreciation && frm.doc.net_purchase_amount) { frm.trigger("set_finance_book"); } else { diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index c048e972882..8618f8a9c15 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -450,10 +450,11 @@ }, { "default": "0", + "depends_on": "eval:(doc.asset_type == \"Existing Asset\" && !doc.calculate_depreciation) || doc.calculate_depreciation", "fieldname": "is_fully_depreciated", "fieldtype": "Check", - "hidden": 1, - "label": "Is Fully Depreciated" + "label": "Is Fully Depreciated", + "read_only_depends_on": "eval:doc.calculate_depreciation" }, { "depends_on": "eval:doc.docstatus > 0", diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index c00ea2b1b3f..5df9f368c2a 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -132,6 +132,10 @@ class Asset(AccountsController): self.validate_gross_and_purchase_amount() self.validate_finance_books() + if self.calculate_depreciation: + # Is Fully Depreciated is only applicable to manually entered existing assets + self.is_fully_depreciated = 0 + def before_save(self): self.total_asset_cost = self.net_purchase_amount + self.additional_asset_cost self.status = self.get_status()