fix: manual depr schedule
This commit is contained in:
@@ -567,19 +567,23 @@ frappe.ui.form.on('Depreciation Schedule', {
|
||||
},
|
||||
|
||||
depreciation_amount: function(frm, cdt, cdn) {
|
||||
erpnext.asset.set_accumulated_depreciation(frm);
|
||||
erpnext.asset.set_accumulated_depreciation(frm, locals[cdt][cdn].finance_book_id);
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
erpnext.asset.set_accumulated_depreciation = function(frm) {
|
||||
if(frm.doc.depreciation_method != "Manual") return;
|
||||
erpnext.asset.set_accumulated_depreciation = function(frm, finance_book_id) {
|
||||
var depreciation_method = frm.doc.finance_books[Number(finance_book_id) - 1].depreciation_method;
|
||||
|
||||
if(depreciation_method != "Manual") return;
|
||||
|
||||
var accumulated_depreciation = flt(frm.doc.opening_accumulated_depreciation);
|
||||
|
||||
$.each(frm.doc.schedules || [], function(i, row) {
|
||||
accumulated_depreciation += flt(row.depreciation_amount);
|
||||
frappe.model.set_value(row.doctype, row.name,
|
||||
"accumulated_depreciation_amount", accumulated_depreciation);
|
||||
if (row.finance_book_id === finance_book_id) {
|
||||
accumulated_depreciation += flt(row.depreciation_amount);
|
||||
frappe.model.set_value(row.doctype, row.name, "accumulated_depreciation_amount", accumulated_depreciation);
|
||||
};
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -84,8 +84,11 @@ class Asset(AccountsController):
|
||||
if self.calculate_depreciation:
|
||||
self.value_after_depreciation = 0
|
||||
self.set_depreciation_rate()
|
||||
self.make_depreciation_schedule(date_of_disposal)
|
||||
self.set_accumulated_depreciation(date_of_disposal, date_of_return)
|
||||
if not (
|
||||
self.get("schedules") and "Manual" in [d.depreciation_method for d in self.finance_books]
|
||||
):
|
||||
self.make_depreciation_schedule(date_of_disposal)
|
||||
self.set_accumulated_depreciation(date_of_disposal, date_of_return)
|
||||
else:
|
||||
self.finance_books = []
|
||||
self.value_after_depreciation = flt(self.gross_purchase_amount) - flt(
|
||||
@@ -225,9 +228,7 @@ class Asset(AccountsController):
|
||||
)
|
||||
|
||||
def make_depreciation_schedule(self, date_of_disposal):
|
||||
if "Manual" not in [d.depreciation_method for d in self.finance_books] and not self.get(
|
||||
"schedules"
|
||||
):
|
||||
if not self.get("schedules"):
|
||||
self.schedules = []
|
||||
|
||||
if not self.available_for_use_date:
|
||||
@@ -556,7 +557,9 @@ class Asset(AccountsController):
|
||||
self, date_of_disposal=None, date_of_return=None, ignore_booked_entry=False
|
||||
):
|
||||
straight_line_idx = [
|
||||
d.idx for d in self.get("schedules") if d.depreciation_method == "Straight Line"
|
||||
d.idx
|
||||
for d in self.get("schedules")
|
||||
if d.depreciation_method == "Straight Line" or d.depreciation_method == "Manual"
|
||||
]
|
||||
finance_books = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user