Merge pull request #50879 from aerele/is-fixed-asset-set-only-once

fix: remove set_only_once from is_fixed_asset field
This commit is contained in:
Khushi Rawat
2025-12-04 12:14:19 +05:30
committed by GitHub
3 changed files with 8 additions and 6 deletions

View File

@@ -230,7 +230,7 @@ frappe.ui.form.on("Item", {
].forEach((fieldname) => { ].forEach((fieldname) => {
frm.set_df_property(fieldname, "read_only", stock_exists); frm.set_df_property(fieldname, "read_only", stock_exists);
}); });
frm.set_df_property("is_fixed_asset", "read_only", frm.doc.__onload?.asset_exists ? 1 : 0);
frm.toggle_reqd("customer", frm.doc.is_customer_provided_item ? 1 : 0); frm.toggle_reqd("customer", frm.doc.is_customer_provided_item ? 1 : 0);
frm.set_query("item_group", () => { frm.set_query("item_group", () => {
return { return {

View File

@@ -247,8 +247,7 @@
"default": "0", "default": "0",
"fieldname": "is_fixed_asset", "fieldname": "is_fixed_asset",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Is Fixed Asset", "label": "Is Fixed Asset"
"set_only_once": 1
}, },
{ {
"allow_in_quick_entry": 1, "allow_in_quick_entry": 1,
@@ -917,7 +916,7 @@
"image_field": "image", "image_field": "image",
"links": [], "links": [],
"make_attachments_public": 1, "make_attachments_public": 1,
"modified": "2025-11-03 17:01:24.555003", "modified": "2025-12-04 09:11:56.029567",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Item", "name": "Item",

View File

@@ -156,6 +156,7 @@ class Item(Document):
self.set_onload("stock_exists", self.stock_ledger_created()) self.set_onload("stock_exists", self.stock_ledger_created())
self.set_onload("asset_naming_series", get_asset_naming_series()) self.set_onload("asset_naming_series", get_asset_naming_series())
self.set_onload("current_valuation_method", get_valuation_method(self.name)) self.set_onload("current_valuation_method", get_valuation_method(self.name))
self.set_onload("asset_exists", self.has_submitted_assets())
def autoname(self): def autoname(self):
if frappe.db.get_default("item_naming_by") == "Naming Series": if frappe.db.get_default("item_naming_by") == "Naming Series":
@@ -308,8 +309,7 @@ class Item(Document):
frappe.throw(_("Cannot be a fixed asset item as Stock Ledger is created.")) frappe.throw(_("Cannot be a fixed asset item as Stock Ledger is created."))
if not self.is_fixed_asset and not self.is_new(): if not self.is_fixed_asset and not self.is_new():
asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1) if self.has_submitted_assets():
if asset:
frappe.throw( frappe.throw(
_('"Is Fixed Asset" cannot be unchecked, as Asset record exists against the item') _('"Is Fixed Asset" cannot be unchecked, as Asset record exists against the item')
) )
@@ -524,6 +524,9 @@ class Item(Document):
) )
return self._stock_ledger_created return self._stock_ledger_created
def has_submitted_assets(self):
return bool(frappe.db.exists("Asset", {"item_code": self.name, "docstatus": 1}))
def update_item_price(self): def update_item_price(self):
if self.is_new(): if self.is_new():
return return