Skip to content

Commit

Permalink
Merge pull request #42593 from khushi8112/disable-submit-button-for-c…
Browse files Browse the repository at this point in the history
…omposite-asset

fix: disable primary action button only when there are no active capitalization
  • Loading branch information
khushi8112 authored Aug 6, 2024
2 parents 82b02d6 + bb877f4 commit b1c23ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
18 changes: 14 additions & 4 deletions erpnext/assets/doctype/asset/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,21 @@ frappe.ui.form.on("Asset", {
frm.toggle_reqd("finance_books", frm.doc.calculate_depreciation);

if (frm.doc.is_composite_asset) {
$(".primary-action").prop("hidden", true);
$(".form-message").text("Capitalize this asset to confirm");
frappe.call({
method: "erpnext.assets.doctype.asset.asset.has_active_capitalization",
args: {
asset: frm.doc.name,
},
callback: function (r) {
if (!r.message) {
$(".primary-action").prop("hidden", true);
$(".form-message").text("Capitalize this asset to confirm");

frm.add_custom_button(__("Capitalize Asset"), function () {
frm.trigger("create_asset_capitalization");
frm.add_custom_button(__("Capitalize Asset"), function () {
frm.trigger("create_asset_capitalization");
});
}
},
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions erpnext/assets/doctype/asset/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@
"read_only": 1
},
{
"depends_on": "eval:!doc.is_composite_asset",
"fieldname": "gross_purchase_amount",
"fieldtype": "Currency",
"label": "Gross Purchase Amount",
Expand Down Expand Up @@ -580,7 +579,7 @@
"link_fieldname": "target_asset"
}
],
"modified": "2024-07-07 22:27:14.733839",
"modified": "2024-08-01 16:39:09.340973",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
Expand Down
8 changes: 8 additions & 0 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,14 @@ def get_asset_value_after_depreciation(asset_name, finance_book=None):
return asset.get_value_after_depreciation(finance_book)


@frappe.whitelist()
def has_active_capitalization(asset):
active_capitalizations = frappe.db.count(
"Asset Capitalization", filters={"target_asset": asset, "docstatus": 1}
)
return active_capitalizations > 0


@frappe.whitelist()
def split_asset(asset_name, split_qty):
asset = frappe.get_doc("Asset", asset_name)
Expand Down

0 comments on commit b1c23ba

Please sign in to comment.