Skip to content

Commit

Permalink
Merge pull request #45293 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-45283

fix: Does not allow to create Sub-Asseblies of Sub Assemblies (backport #45283)
  • Loading branch information
rohitwaghchaure authored Jan 16, 2025
2 parents a11c15a + d3c9092 commit c789171
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions erpnext/manufacturing/doctype/bom_creator/bom_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,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):
Expand Down Expand Up @@ -418,6 +412,8 @@ def add_sub_assembly(**kwargs):
parent_row_no = ""
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",
{
Expand All @@ -426,6 +422,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,
Expand All @@ -437,9 +434,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)
Expand Down Expand Up @@ -471,6 +466,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):
Expand Down

0 comments on commit c789171

Please sign in to comment.