chore: refactor chart and manual set_accumulated_depreciation logic
This commit is contained in:
parent
ca8c827492
commit
83ed93fbb6
@ -187,7 +187,11 @@ frappe.ui.form.on('Asset', {
|
||||
})
|
||||
},
|
||||
|
||||
setup_chart: function(frm) {
|
||||
setup_chart: async function(frm) {
|
||||
if(frm.doc.finance_books.length > 1) {
|
||||
return
|
||||
}
|
||||
|
||||
var x_intervals = [frm.doc.purchase_date];
|
||||
var asset_values = [frm.doc.gross_purchase_amount];
|
||||
var last_depreciation_date = frm.doc.purchase_date;
|
||||
@ -201,7 +205,19 @@ frappe.ui.form.on('Asset', {
|
||||
flt(frm.doc.opening_accumulated_depreciation));
|
||||
}
|
||||
|
||||
$.each(frm.doc.schedules || [], function(i, v) {
|
||||
let depr_schedule = [];
|
||||
|
||||
if (frm.doc.finance_books.length == 1) {
|
||||
depr_schedule = (await frappe.call(
|
||||
"erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule.get_depr_schedule_from_asset_depr_schedule_of_asset",
|
||||
{
|
||||
asset_name: frm.doc.name,
|
||||
finance_book: frm.doc.finance_books[0].finance_book || null
|
||||
}
|
||||
)).message;
|
||||
}
|
||||
|
||||
$.each(depr_schedule || [], function(i, v) {
|
||||
x_intervals.push(v.schedule_date);
|
||||
var asset_value = flt(frm.doc.gross_purchase_amount) - flt(v.accumulated_depreciation_amount);
|
||||
if(v.journal_entry) {
|
||||
@ -265,10 +281,6 @@ frappe.ui.form.on('Asset', {
|
||||
// frm.toggle_reqd("next_depreciation_date", (!frm.doc.is_existing_asset && frm.doc.calculate_depreciation));
|
||||
},
|
||||
|
||||
opening_accumulated_depreciation: function(frm) {
|
||||
erpnext.asset.set_accumulated_depreciation(frm);
|
||||
},
|
||||
|
||||
make_schedules_editable: function(frm) {
|
||||
if (frm.doc.finance_books) {
|
||||
var is_editable = frm.doc.finance_books.filter(d => d.depreciation_method == "Manual").length > 0
|
||||
@ -511,17 +523,6 @@ frappe.ui.form.on('Asset Finance Book', {
|
||||
}
|
||||
});
|
||||
|
||||
erpnext.asset.set_accumulated_depreciation = function(frm) {
|
||||
if(frm.doc.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);
|
||||
})
|
||||
};
|
||||
|
||||
erpnext.asset.scrap_asset = function(frm) {
|
||||
frappe.confirm(__("Do you really want to scrap this asset?"), function () {
|
||||
frappe.call({
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
frappe.provide("erpnext.asset");
|
||||
|
||||
frappe.ui.form.on('Depreciation Schedule', {
|
||||
make_depreciation_entry: function(frm, cdt, cdn) {
|
||||
@ -22,4 +23,15 @@ frappe.ui.form.on('Depreciation Schedule', {
|
||||
depreciation_amount: function(frm, cdt, cdn) {
|
||||
erpnext.asset.set_accumulated_depreciation(frm);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
erpnext.asset.set_accumulated_depreciation = function(frm) {
|
||||
if(frm.doc.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);
|
||||
})
|
||||
};
|
||||
|
@ -10,6 +10,7 @@
|
||||
"asset",
|
||||
"naming_series",
|
||||
"column_break_2",
|
||||
"opening_accumulated_depreciation",
|
||||
"finance_book",
|
||||
"finance_book_id",
|
||||
"depreciation_details_section",
|
||||
@ -151,7 +152,15 @@
|
||||
"label": "Finance Book Id",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"depends_on": "opening_accumulated_depreciation",
|
||||
"fieldname": "opening_accumulated_depreciation",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Opening Accumulated Depreciation",
|
||||
"read_only": 1,
|
||||
"options": "Company:company:default_currency"
|
||||
}
|
||||
],
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
|
@ -150,6 +150,7 @@ def get_asset_depr_schedule_name(asset_name, finance_book):
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_depr_schedule_from_asset_depr_schedule_of_asset(asset_name, finance_book):
|
||||
asset_depr_schedule_name = get_asset_depr_schedule_name(asset_name, finance_book)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user