Skip to content

Commit

Permalink
refactor!: dynamically compute bom_level
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Jan 30, 2022
1 parent 0f7c2a1 commit 157b4b3
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 67 deletions.
11 changes: 2 additions & 9 deletions erpnext/manufacturing/doctype/bom/bom.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"inspection_required",
"quality_inspection_template",
"column_break_31",
"bom_level",
"section_break_33",
"items",
"scrap_section",
Expand Down Expand Up @@ -522,13 +521,6 @@
"fieldname": "column_break_31",
"fieldtype": "Column Break"
},
{
"default": "0",
"fieldname": "bom_level",
"fieldtype": "Int",
"label": "BOM Level",
"read_only": 1
},
{
"fieldname": "section_break_33",
"fieldtype": "Section Break",
Expand All @@ -540,7 +532,7 @@
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2021-11-18 13:04:16.271975",
"modified": "2022-01-30 21:27:54.727298",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM",
Expand Down Expand Up @@ -577,5 +569,6 @@
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
15 changes: 0 additions & 15 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def validate(self):
self.calculate_cost()
self.update_stock_qty()
self.update_cost(update_parent=False, from_child_bom=True, update_hour_rate = False, save=False)
self.set_bom_level()
self.validate_scrap_items()

def get_context(self, context):
Expand Down Expand Up @@ -716,20 +715,6 @@ def get_tree_representation(self) -> BOMTree:
"""Get a complete tree representation preserving order of child items."""
return BOMTree(self.name)

def set_bom_level(self, update=False):
levels = []

self.bom_level = 0
for row in self.items:
if row.bom_no:
levels.append(frappe.get_cached_value("BOM", row.bom_no, "bom_level") or 0)

if levels:
self.bom_level = max(levels) + 1

if update:
self.db_set("bom_level", self.bom_level)

def validate_scrap_items(self):
for item in self.scrap_items:
msg = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def get_sub_assembly_items(self, manufacturing_type=None):
self.set_sub_assembly_items_based_on_level(row, bom_data, manufacturing_type)

def set_sub_assembly_items_based_on_level(self, row, bom_data, manufacturing_type=None):
bom_data = sorted(bom_data, key = lambda i: i.bom_level)
bom_data = sorted(bom_data, key = lambda i: i.bom_level, reverse=True)

for data in bom_data:
data.qty = data.stock_qty
Expand Down Expand Up @@ -1004,9 +1004,6 @@ def get_sub_assembly_items(bom_no, bom_data, to_produce_qty, indent=0):
for d in data:
if d.expandable:
parent_item_code = frappe.get_cached_value("BOM", bom_no, "item")
bom_level = (frappe.get_cached_value("BOM", d.value, "bom_level")
if d.value else 0)

stock_qty = (d.stock_qty / d.parent_bom_qty) * flt(to_produce_qty)
bom_data.append(frappe._dict({
'parent_item_code': parent_item_code,
Expand All @@ -1017,7 +1014,7 @@ def get_sub_assembly_items(bom_no, bom_data, to_produce_qty, indent=0):
'uom': d.stock_uom,
'bom_no': d.value,
'is_sub_contracted_item': d.is_sub_contracted_item,
'bom_level': bom_level,
'bom_level': indent,
'indent': indent,
'stock_qty': stock_qty
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
},
{
"columns": 1,
"fetch_from": "bom_no.bom_level",
"fieldname": "bom_level",
"fieldtype": "Int",
"in_list_view": 1,
Expand Down Expand Up @@ -189,7 +188,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-06-28 20:10:56.296410",
"modified": "2022-01-30 21:31:10.527559",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan Sub Assembly Item",
Expand All @@ -198,5 +197,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
5 changes: 2 additions & 3 deletions erpnext/manufacturing/report/bom_explorer/bom_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def get_exploded_items(bom, data, indent=0, qty=1):
'item_code': item.item_code,
'item_name': item.item_name,
'indent': indent,
'bom_level': (frappe.get_cached_value("BOM", item.bom_no, "bom_level")
if item.bom_no else ""),
'bom_level': indent,
'bom': item.bom_no,
'qty': item.qty * qty,
'uom': item.uom,
Expand Down Expand Up @@ -73,7 +72,7 @@ def get_columns():
},
{
"label": "BOM Level",
"fieldtype": "Data",
"fieldtype": "Int",
"fieldname": "bom_level",
"width": 100
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_production_plan_item_details(filters, data, order_details):
"qty": row.planned_qty,
"document_type": "Work Order",
"document_name": work_order or "",
"bom_level": frappe.get_cached_value("BOM", row.bom_no, "bom_level"),
"bom_level": 0,
"produced_qty": order_details.get((work_order, row.item_code), {}).get("produced_qty", 0),
"pending_qty": flt(row.planned_qty) - flt(order_details.get((work_order, row.item_code), {}).get("produced_qty", 0))
})
Expand Down
1 change: 0 additions & 1 deletion erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ erpnext.patches.v13_0.bill_for_rejected_quantity_in_purchase_invoice
erpnext.patches.v13_0.rename_issue_status_hold_to_on_hold
erpnext.patches.v13_0.update_response_by_variance
erpnext.patches.v13_0.update_job_card_details
erpnext.patches.v13_0.update_level_in_bom #1234sswef
erpnext.patches.v13_0.add_missing_fg_item_for_stock_entry
erpnext.patches.v13_0.update_subscription_status_in_memberships
erpnext.patches.v13_0.update_amt_in_work_order_required_items
Expand Down
31 changes: 0 additions & 31 deletions erpnext/patches/v13_0/update_level_in_bom.py

This file was deleted.

0 comments on commit 157b4b3

Please sign in to comment.