fix(UI): improve asset action buttons group

(cherry picked from commit e90a3b5a56)
This commit is contained in:
khushi8112
2026-02-05 12:50:24 +05:30
parent 4d0e28a608
commit 78074c0cdd
3 changed files with 154 additions and 74 deletions

View File

@@ -86,47 +86,44 @@ frappe.ui.form.on("Asset", {
}
},
refresh: function (frm) {
refresh: async function (frm) {
frappe.ui.form.trigger("Asset", "asset_type");
frm.toggle_display("next_depreciation_date", frm.doc.docstatus < 1);
let has_create_buttons = false;
if (frm.doc.docstatus == 1) {
if (["Submitted", "Partially Depreciated", "Fully Depreciated"].includes(frm.doc.status)) {
if (["Submitted", "Partially Depreciated"].includes(frm.doc.status)) {
frm.add_custom_button(
__("Transfer Asset"),
__("Asset Value Adjustment"),
function () {
erpnext.asset.transfer_asset(frm);
frm.trigger("create_asset_value_adjustment");
},
__("Manage")
__("Create")
);
frm.add_custom_button(
__("Scrap Asset"),
__("Asset Repair"),
function () {
erpnext.asset.scrap_asset(frm);
frm.trigger("create_asset_repair");
},
__("Manage")
__("Create")
);
has_create_buttons = true;
}
if (!frm.doc.calculate_depreciation) {
frm.add_custom_button(
__("Sell Asset"),
__("Depreciation Entry"),
function () {
frm.trigger("sell_asset");
frm.trigger("make_journal_entry");
},
__("Manage")
__("Create")
);
has_create_buttons = true;
}
frm.add_custom_button(
__("Split Asset"),
function () {
frm.trigger("split_asset");
},
__("Manage")
);
} else if (frm.doc.status == "Scrapped") {
frm.add_custom_button(__("Restore Asset"), function () {
erpnext.asset.restore_asset(frm);
}).addClass("btn-primary");
if (has_create_buttons) {
cur_frm.page.set_inner_btn_group_as_primary(__("Create"));
}
if (frm.doc.maintenance_required && !frm.doc.maintenance_schedule) {
@@ -135,41 +132,51 @@ frappe.ui.form.on("Asset", {
function () {
frm.trigger("create_asset_maintenance");
},
__("Manage")
__("Actions")
);
}
if (["Submitted", "Partially Depreciated"].includes(frm.doc.status)) {
if (["Submitted", "Partially Depreciated", "Fully Depreciated"].includes(frm.doc.status)) {
frm.add_custom_button(
__("Adjust Asset Value"),
__("Split Asset"),
function () {
frm.trigger("create_asset_value_adjustment");
frm.trigger("split_asset");
},
__("Manage")
__("Actions")
);
frm.add_custom_button(
__("Repair Asset"),
__("Transfer Asset"),
function () {
frm.trigger("create_asset_repair");
erpnext.asset.transfer_asset(frm);
},
__("Manage")
__("Actions")
);
frm.add_custom_button(
__("Scrap Asset"),
function () {
erpnext.asset.scrap_asset(frm);
},
__("Actions")
);
frm.add_custom_button(
__("Sell Asset"),
function () {
frm.trigger("sell_asset");
},
__("Actions")
);
} else if (frm.doc.status == "Scrapped") {
frm.add_custom_button(__("Restore Asset"), function () {
erpnext.asset.restore_asset(frm);
}).addClass("btn-primary");
}
if (!frm.doc.calculate_depreciation) {
if (await frm.events.should_show_accounting_ledger(frm)) {
frm.add_custom_button(
__("Create Depreciation Entry"),
function () {
frm.trigger("make_journal_entry");
},
__("Manage")
);
}
if (frm.doc.purchase_receipt || !frm.doc.asset_type == "Existing Asset") {
frm.add_custom_button(
__("View General Ledger"),
__("Accounting Ledger"),
function () {
frappe.route_options = {
voucher_no: frm.doc.name,
@@ -179,7 +186,7 @@ frappe.ui.form.on("Asset", {
};
frappe.set_route("query-report", "General Ledger");
},
__("Manage")
__("View")
);
}
@@ -217,6 +224,27 @@ frappe.ui.form.on("Asset", {
}
},
should_show_accounting_ledger: async function (frm) {
if (["Capitalized"].includes(frm.doc.status)) {
return false;
}
if (
!frm.doc.purchase_receipt &&
["Existing Asset", "Composite Component"].includes(frm.doc.asset_type)
) {
return false;
}
const asset_category = await frappe.db.get_value(
"Asset Category",
frm.doc.asset_category,
"enable_cwip_accounting"
);
return !!asset_category.message?.enable_cwip_accounting;
},
set_depr_posting_failure_alert: function (frm) {
const alert = `
<div class="row">

View File

@@ -9,18 +9,17 @@
"engine": "InnoDB",
"field_order": [
"naming_series",
"company",
"item_code",
"item_name",
"asset_name",
"asset_category",
"location",
"image",
"column_break_3",
"company",
"asset_owner",
"asset_owner_company",
"customer",
"supplier",
"location",
"asset_category",
"asset_type",
"maintenance_required",
"calculate_depreciation",
"purchase_details_section",
"purchase_receipt",
"purchase_receipt_item",
@@ -34,25 +33,38 @@
"purchase_amount",
"asset_quantity",
"additional_asset_cost",
"section_break_uiyd",
"column_break_bbwr",
"column_break_bfkm",
"total_asset_cost",
"depreciation_tab",
"calculate_depreciation",
"column_break_33",
"column_break_wqzi",
"opening_accumulated_depreciation",
"opening_number_of_booked_depreciations",
"is_fully_depreciated",
"column_break_33",
"opening_number_of_booked_depreciations",
"section_break_36",
"finance_books",
"section_break_33",
"depreciation_method",
"value_after_depreciation",
"total_number_of_depreciations",
"column_break_24",
"frequency_of_depreciation",
"column_break_24",
"next_depreciation_date",
"total_number_of_depreciations",
"depreciation_schedule_sb",
"depreciation_schedule_view",
"insurance_details_tab",
"other_info_tab",
"accounting_dimensions_section",
"cost_center",
"column_break_rjyw",
"asset_owner_section",
"asset_owner",
"column_break_yeds",
"asset_owner_company",
"customer",
"supplier",
"insurance_section",
"policy_number",
"insurer",
"insured_value",
@@ -60,21 +72,17 @@
"insurance_start_date",
"insurance_end_date",
"comprehensive_insurance",
"other_info_tab",
"accounting_dimensions_section",
"cost_center",
"section_break_jtou",
"status",
"custodian",
"department",
"default_finance_book",
"depr_entry_posting_status",
"booked_fixed_asset",
"column_break_51",
"department",
"split_from",
"journal_entry_for_scrap",
"split_from",
"amended_from",
"maintenance_required",
"booked_fixed_asset",
"connections_tab"
],
"fields": [
@@ -246,13 +254,14 @@
{
"fieldname": "section_break_33",
"fieldtype": "Section Break",
"hidden": 1
"hidden": 1,
"label": "Depreciation Details"
},
{
"fieldname": "depreciation_method",
"fieldtype": "Select",
"label": "Depreciation Method",
"options": "\nStraight Line\nDouble Declining Balance\nManual"
"options": "\nStraight Line\nDouble Declining Balance\nWritten Down Value\nManual"
},
{
"fieldname": "value_after_depreciation",
@@ -279,6 +288,7 @@
{
"fieldname": "next_depreciation_date",
"fieldtype": "Date",
"hidden": 1,
"label": "Next Depreciation Date",
"no_copy": 1
},
@@ -397,7 +407,7 @@
"fieldtype": "Column Break"
},
{
"depends_on": "calculate_depreciation",
"depends_on": "eval: doc.calculate_depreciation",
"fieldname": "section_break_36",
"fieldtype": "Section Break"
},
@@ -441,6 +451,7 @@
"depends_on": "eval:(doc.asset_type == \"Existing Asset\")",
"fieldname": "is_fully_depreciated",
"fieldtype": "Check",
"hidden": 1,
"label": "Is Fully Depreciated"
},
{
@@ -489,15 +500,10 @@
"hidden": 1,
"label": "Purchase Invoice Item"
},
{
"fieldname": "insurance_details_tab",
"fieldtype": "Tab Break",
"label": "Insurance"
},
{
"fieldname": "other_info_tab",
"fieldtype": "Tab Break",
"label": "Other Info"
"label": "More Info"
},
{
"fieldname": "connections_tab",
@@ -506,6 +512,7 @@
"show_dashboard": 1
},
{
"depends_on": "eval: doc.calculate_depreciation || doc.asset_type == \"Existing Asset\"",
"fieldname": "depreciation_tab",
"fieldtype": "Tab Break",
"label": "Depreciation"
@@ -533,6 +540,48 @@
"fieldtype": "Select",
"label": "Asset Type",
"options": "\nExisting Asset\nComposite Asset\nComposite Component"
},
{
"fieldname": "column_break_wqzi",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_rjyw",
"fieldtype": "Column Break"
},
{
"fieldname": "insurance_section",
"fieldtype": "Section Break",
"label": "Insurance"
},
{
"fieldname": "section_break_uiyd",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_bbwr",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_bfkm",
"fieldtype": "Column Break"
},
{
"fetch_from": "item_code.item_name",
"fetch_if_empty": 1,
"fieldname": "item_name",
"fieldtype": "Read Only",
"hidden": 1,
"label": "Item Name"
},
{
"fieldname": "asset_owner_section",
"fieldtype": "Section Break",
"label": "Ownership"
},
{
"fieldname": "column_break_yeds",
"fieldtype": "Column Break"
}
],
"idx": 72,
@@ -576,7 +625,7 @@
"link_fieldname": "target_asset"
}
],
"modified": "2026-02-03 15:48:13.407835",
"modified": "2026-02-05 12:42:45.350216",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",

View File

@@ -68,7 +68,9 @@ class Asset(AccountsController):
default_finance_book: DF.Link | None
department: DF.Link | None
depr_entry_posting_status: DF.Literal["", "Successful", "Failed"]
depreciation_method: DF.Literal["", "Straight Line", "Double Declining Balance", "Manual"]
depreciation_method: DF.Literal[
"", "Straight Line", "Double Declining Balance", "Written Down Value", "Manual"
]
disposal_date: DF.Date | None
finance_books: DF.Table[AssetFinanceBook]
frequency_of_depreciation: DF.Int
@@ -79,6 +81,7 @@ class Asset(AccountsController):
insurer: DF.Data | None
is_fully_depreciated: DF.Check
item_code: DF.Link
item_name: DF.ReadOnly | None
journal_entry_for_scrap: DF.Link | None
location: DF.Link
maintenance_required: DF.Check