From 5d1ffa7fcae2bd391cea8ab0656f9b37e821cd71 Mon Sep 17 00:00:00 2001 From: Henil Date: Wed, 9 Sep 2026 16:34:20 +0530 Subject: [PATCH 1/3] fix(assets): build Finance Books even when Calculate Depreciation is checked before Net Purchase Amount is entered Previously, checking "Calculate Depreciation" (or picking the Item) before typing in "Net Purchase Amount" left the Finance Books table empty, because the depreciation schedule was only built at the moment those fields already had values. Entering the amount afterward only updated existing Finance Books rows, so an empty table stayed empty. Now, entering the amount also builds Finance Books from scratch if it was left empty, regardless of the order fields were filled in. --- erpnext/assets/doctype/asset/asset.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index e269f289307..8c7f0b1f788 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -735,10 +735,14 @@ frappe.ui.form.on("Asset", { }, net_purchase_amount: function (frm) { - if (frm.doc.finance_books) { + if (frm.doc.finance_books && frm.doc.finance_books.length) { frm.doc.finance_books.forEach((d) => { frm.events.set_depreciation_rate(frm, d); }); + } else if (frm.doc.item_code && frm.doc.calculate_depreciation && frm.doc.net_purchase_amount) { + // "Calculate Depreciation" (or the Item) was set before an amount existed, so the + // finance books table was left empty -- build it now that there's an amount to base it on. + frm.trigger("set_finance_book"); } }, From 5a8126412ab11bb70aa13bda4fe28d599bdfeb08 Mon Sep 17 00:00:00 2001 From: Henil Date: Fri, 11 Sep 2026 13:02:04 +0530 Subject: [PATCH 2/3] fix(assets): discard stale set_finance_book responses Rapid successive edits to Net Purchase Amount could fire overlapping set_finance_book calls; if an older request's response arrived after a newer one, it could overwrite Finance Books with values computed from a stale amount. Now the callback only applies a response if the fields it was based on still match the form's current values. --- erpnext/assets/doctype/asset/asset.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index 8c7f0b1f788..64ad9f370b3 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -533,15 +533,25 @@ frappe.ui.form.on("Asset", { }, set_finance_book: function (frm) { + // Snapshot the fields this request is based on, so a stale response from an + // earlier, still-in-flight call (e.g. from rapid successive amount edits) + // can't overwrite Finance Books with values computed from an old amount. + let item_code = frm.doc.item_code; + let net_purchase_amount = frm.doc.net_purchase_amount; + frappe.call({ method: "erpnext.assets.doctype.asset.asset.get_item_details", args: { - item_code: frm.doc.item_code, + item_code: item_code, asset_category: frm.doc.asset_category, - net_purchase_amount: frm.doc.net_purchase_amount, + net_purchase_amount: net_purchase_amount, }, callback: function (r, rt) { - if (r.message) { + if ( + r.message && + frm.doc.item_code === item_code && + frm.doc.net_purchase_amount === net_purchase_amount + ) { frm.set_value("finance_books", r.message); } }, From 514c3b45d0ef1646143a75d7870ae0bb0f239557 Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Tue, 15 Sep 2026 23:56:20 +0530 Subject: [PATCH 3/3] chore: remove unnecessary comments --- erpnext/assets/doctype/asset/asset.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index 64ad9f370b3..e073a6cfb96 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -533,9 +533,6 @@ frappe.ui.form.on("Asset", { }, set_finance_book: function (frm) { - // Snapshot the fields this request is based on, so a stale response from an - // earlier, still-in-flight call (e.g. from rapid successive amount edits) - // can't overwrite Finance Books with values computed from an old amount. let item_code = frm.doc.item_code; let net_purchase_amount = frm.doc.net_purchase_amount; @@ -750,8 +747,6 @@ frappe.ui.form.on("Asset", { frm.events.set_depreciation_rate(frm, d); }); } else if (frm.doc.item_code && frm.doc.calculate_depreciation && frm.doc.net_purchase_amount) { - // "Calculate Depreciation" (or the Item) was set before an amount existed, so the - // finance books table was left empty -- build it now that there's an amount to base it on. frm.trigger("set_finance_book"); } },