fix: show depr schedule table in asset doc (#36332)
This commit is contained in:
parent
f368894d22
commit
f28f8dc596
@ -141,7 +141,7 @@ frappe.ui.form.on('Asset', {
|
||||
frm.trigger("set_depr_posting_failure_alert");
|
||||
}
|
||||
|
||||
frm.trigger("setup_chart");
|
||||
frm.trigger("setup_chart_and_depr_schedule_view");
|
||||
}
|
||||
|
||||
frm.trigger("toggle_reference_doc");
|
||||
@ -206,7 +206,38 @@ frappe.ui.form.on('Asset', {
|
||||
})
|
||||
},
|
||||
|
||||
setup_chart: async function(frm) {
|
||||
render_depreciation_schedule_view: function(frm, depr_schedule) {
|
||||
var wrapper = $(frm.fields_dict["depreciation_schedule_view"].wrapper).empty();
|
||||
|
||||
let table = $(`<table class="table table-bordered" style="margin-top:0px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<td align="center">${__("No.")}</td>
|
||||
<td>${__("Schedule Date")}</td>
|
||||
<td align="right">${__("Depreciation Amount")}</td>
|
||||
<td align="right">${__("Accumulated Depreciation Amount")}</td>
|
||||
<td>${__("Journal Entry")}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>`);
|
||||
|
||||
depr_schedule.forEach((sch) => {
|
||||
const row = $(`<tr>
|
||||
<td align="center">${sch['idx']}</td>
|
||||
<td><b>${frappe.format(sch['schedule_date'], { fieldtype: 'Date' })}</b></td>
|
||||
<td><b>${frappe.format(sch['depreciation_amount'], { fieldtype: 'Currency' })}</b></td>
|
||||
<td>${frappe.format(sch['accumulated_depreciation_amount'], { fieldtype: 'Currency' })}</td>
|
||||
<td><a href="/app/journal-entry/${sch['journal_entry'] || ''}">${sch['journal_entry'] || ''}</a></td>
|
||||
</tr>`);
|
||||
table.find("tbody").append(row);
|
||||
});
|
||||
|
||||
wrapper.append(table);
|
||||
|
||||
},
|
||||
|
||||
setup_chart_and_depr_schedule_view: async function(frm) {
|
||||
if(frm.doc.finance_books.length > 1) {
|
||||
return
|
||||
}
|
||||
@ -228,7 +259,7 @@ frappe.ui.form.on('Asset', {
|
||||
"erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule.get_depr_schedule",
|
||||
{
|
||||
asset_name: frm.doc.name,
|
||||
status: frm.doc.docstatus ? "Active" : "Draft",
|
||||
status: "Active",
|
||||
finance_book: frm.doc.finance_books[0].finance_book || null
|
||||
}
|
||||
)).message;
|
||||
@ -246,6 +277,9 @@ frappe.ui.form.on('Asset', {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frm.toggle_display(["depreciation_schedule_view"], 1);
|
||||
frm.events.render_depreciation_schedule_view(frm, depr_schedule);
|
||||
} else {
|
||||
if(frm.doc.opening_accumulated_depreciation) {
|
||||
x_intervals.push(frappe.format(frm.doc.creation.split(" ")[0], { fieldtype: 'Date' }));
|
||||
|
@ -52,6 +52,8 @@
|
||||
"column_break_24",
|
||||
"frequency_of_depreciation",
|
||||
"next_depreciation_date",
|
||||
"depreciation_schedule_sb",
|
||||
"depreciation_schedule_view",
|
||||
"insurance_details",
|
||||
"policy_number",
|
||||
"insurer",
|
||||
@ -487,6 +489,17 @@
|
||||
"options": "\nSuccessful\nFailed",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "depreciation_schedule_sb",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Depreciation Schedule"
|
||||
},
|
||||
{
|
||||
"fieldname": "depreciation_schedule_view",
|
||||
"fieldtype": "HTML",
|
||||
"hidden": 1,
|
||||
"label": "Depreciation Schedule View"
|
||||
}
|
||||
],
|
||||
"idx": 72,
|
||||
@ -520,7 +533,7 @@
|
||||
"table_fieldname": "accounts"
|
||||
}
|
||||
],
|
||||
"modified": "2023-03-30 15:07:41.542374",
|
||||
"modified": "2023-07-26 13:33:36.821534",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset",
|
||||
|
@ -21,6 +21,7 @@ from frappe.utils import (
|
||||
import erpnext
|
||||
from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
||||
from erpnext.assets.doctype.asset.depreciation import (
|
||||
get_comma_separated_links,
|
||||
get_depreciation_accounts,
|
||||
get_disposal_account_and_cost_center,
|
||||
)
|
||||
@ -59,8 +60,17 @@ class Asset(AccountsController):
|
||||
if not self.booked_fixed_asset and self.validate_make_gl_entry():
|
||||
self.make_gl_entries()
|
||||
if not self.split_from:
|
||||
make_draft_asset_depr_schedules_if_not_present(self)
|
||||
asset_depr_schedules_names = make_draft_asset_depr_schedules_if_not_present(self)
|
||||
convert_draft_asset_depr_schedules_into_active(self)
|
||||
if asset_depr_schedules_names:
|
||||
asset_depr_schedules_links = get_comma_separated_links(
|
||||
asset_depr_schedules_names, "Asset Depreciation Schedule"
|
||||
)
|
||||
frappe.msgprint(
|
||||
_(
|
||||
"Asset Depreciation Schedules created:<br>{0}<br><br>Please check, edit if needed, and submit the Asset."
|
||||
).format(asset_depr_schedules_links)
|
||||
)
|
||||
|
||||
def on_cancel(self):
|
||||
self.validate_cancellation()
|
||||
@ -74,7 +84,15 @@ class Asset(AccountsController):
|
||||
|
||||
def after_insert(self):
|
||||
if not self.split_from:
|
||||
make_draft_asset_depr_schedules(self)
|
||||
asset_depr_schedules_names = make_draft_asset_depr_schedules(self)
|
||||
asset_depr_schedules_links = get_comma_separated_links(
|
||||
asset_depr_schedules_names, "Asset Depreciation Schedule"
|
||||
)
|
||||
frappe.msgprint(
|
||||
_(
|
||||
"Asset Depreciation Schedules created:<br>{0}<br><br>Please check, edit if needed, and submit the Asset."
|
||||
).format(asset_depr_schedules_links)
|
||||
)
|
||||
|
||||
def validate_asset_and_reference(self):
|
||||
if self.purchase_invoice or self.purchase_receipt:
|
||||
|
@ -571,6 +571,8 @@ def get_wdv_or_dd_depr_amount(
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedules_if_not_present(asset_doc):
|
||||
asset_depr_schedules_names = []
|
||||
|
||||
for row in asset_doc.get("finance_books"):
|
||||
draft_asset_depr_schedule_name = get_asset_depr_schedule_name(
|
||||
asset_doc.name, "Draft", row.finance_book
|
||||
@ -581,12 +583,20 @@ def make_draft_asset_depr_schedules_if_not_present(asset_doc):
|
||||
)
|
||||
|
||||
if not draft_asset_depr_schedule_name and not active_asset_depr_schedule_name:
|
||||
make_draft_asset_depr_schedule(asset_doc, row)
|
||||
name = make_draft_asset_depr_schedule(asset_doc, row)
|
||||
asset_depr_schedules_names.append(name)
|
||||
|
||||
return asset_depr_schedules_names
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedules(asset_doc):
|
||||
asset_depr_schedules_names = []
|
||||
|
||||
for row in asset_doc.get("finance_books"):
|
||||
make_draft_asset_depr_schedule(asset_doc, row)
|
||||
name = make_draft_asset_depr_schedule(asset_doc, row)
|
||||
asset_depr_schedules_names.append(name)
|
||||
|
||||
return asset_depr_schedules_names
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedule(asset_doc, row):
|
||||
@ -596,6 +606,8 @@ def make_draft_asset_depr_schedule(asset_doc, row):
|
||||
|
||||
asset_depr_schedule_doc.insert()
|
||||
|
||||
return asset_depr_schedule_doc.name
|
||||
|
||||
|
||||
def update_draft_asset_depr_schedules(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
|
@ -53,7 +53,7 @@
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"depends_on": "eval:(doc.docstatus==1 && !doc.journal_entry && doc.schedule_date <= get_today())",
|
||||
"depends_on": "eval:(doc.docstatus==1 && !doc.journal_entry && doc.schedule_date <= frappe.datetime.now_date())",
|
||||
"fieldname": "make_depreciation_entry",
|
||||
"fieldtype": "Button",
|
||||
"label": "Make Depreciation Entry"
|
||||
@ -61,7 +61,7 @@
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-03-13 23:17:15.849950",
|
||||
"modified": "2023-07-26 12:56:48.718736",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Depreciation Schedule",
|
||||
|
Loading…
Reference in New Issue
Block a user