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 <noreply@anthropic.com>
This commit is contained in:
Mohd Haris
2026-06-26 17:34:49 +05:30
parent 1e2adc0706
commit a7c1ebacbe
3 changed files with 16 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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",

View File

@@ -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()