Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Does not allow to create Sub-Asseblies of Sub Assemblies #45283

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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):
Expand Down Expand Up @@ -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",
{
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
Loading