From 318a945d66307fa1afacf228cb26298ccf739f78 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 15 Jan 2025 18:15:52 +0530 Subject: [PATCH] fix: Does not allow to create Sub-Asseblies of Sub Assemblies --- .../doctype/bom_creator/bom_creator.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom_creator/bom_creator.py b/erpnext/manufacturing/doctype/bom_creator/bom_creator.py index 716b0f0eb12f..59f8fb8178c6 100644 --- a/erpnext/manufacturing/doctype/bom_creator/bom_creator.py +++ b/erpnext/manufacturing/doctype/bom_creator/bom_creator.py @@ -391,12 +391,6 @@ def get_children(doctype=None, parent=None, **kwargs): return frappe.get_all("BOM Creator Item", fields=fields, filters=query_filters, order_by="idx") -def get_parent_row_no(doc, name): - for row in doc.items: - if row.name == name: - return row.idx - - @frappe.whitelist() def add_item(**kwargs): if isinstance(kwargs, str): @@ -445,6 +439,8 @@ def add_sub_assembly(**kwargs): if not kwargs.convert_to_sub_assembly: item_info = get_item_details(bom_item.item_code) + parent_row_no = get_parent_row_no(doc, kwargs.fg_reference_id) + item_row = doc.append( "items", { @@ -453,6 +449,7 @@ def add_sub_assembly(**kwargs): "uom": item_info.stock_uom, "fg_item": kwargs.fg_item, "conversion_factor": 1, + "parent_row_no": parent_row_no, "fg_reference_id": name, "stock_qty": bom_item.qty, "do_not_explode": 1, @@ -465,9 +462,7 @@ def add_sub_assembly(**kwargs): parent_row_no = item_row.idx name = "" else: - parent_row_no = [row.idx for row in doc.items if row.name == kwargs.fg_reference_id] - if parent_row_no: - parent_row_no = parent_row_no[0] + parent_row_no = get_parent_row_no(doc, kwargs.fg_reference_id) for row in bom_item.get("items"): row = frappe._dict(row) @@ -500,6 +495,14 @@ def get_item_details(item_code): ) +def get_parent_row_no(doc, name): + for row in doc.items: + if row.name == name: + return row.idx + + frappe.msgprint(_("Parent Row No not found for {0}").format(name)) + + @frappe.whitelist() def delete_node(**kwargs): if isinstance(kwargs, str):