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.

(cherry picked from commit 5d1ffa7fca)
This commit is contained in:
Henil
2026-09-09 16:34:20 +05:30
committed by Mergify
parent 105f62fa2c
commit 1652f6ea42

View File

@@ -752,10 +752,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");
}
},