fix: restrict fixed asset items in the BOM

This commit is contained in:
Rohit Waghchaure
2025-08-08 19:00:32 +05:30
parent 94c45d1db3
commit 760c373eb2

View File

@@ -10,7 +10,7 @@ import frappe
from frappe import _, bold
from frappe.core.doctype.version.version import get_diff
from frappe.model.mapper import get_mapped_doc
from frappe.utils import cint, cstr, flt, parse_json, today
from frappe.utils import cint, cstr, flt, get_link_to_form, parse_json, today
from frappe.website.website_generator import WebsiteGenerator
import erpnext
@@ -652,12 +652,23 @@ class BOM(WebsiteGenerator):
frappe.throw(_("Raw Materials cannot be blank."))
check_list = []
items = []
for m in self.get("items"):
if m.bom_no:
validate_bom_no(m.item_code, m.bom_no)
if flt(m.qty) <= 0:
frappe.throw(_("Quantity required for Item {0} in row {1}").format(m.item_code, m.idx))
check_list.append(m)
items.append(m.item_code)
if fixed_asset_items := frappe.db.get_all(
"Item", filters={"item_code": ("in", items), "is_fixed_asset": 1}, pluck="name"
):
frappe.throw(
_("Fixed Asset item {0} cannot be used in BOMs.").format(
", ".join(get_link_to_form("Item", item) for item in fixed_asset_items)
)
)
def check_recursion(self, bom_list=None):
"""Check whether recursion occurs in any bom"""