fix: incorrect qty calculation in the production plan fopr the sub assembely work orders (#18970)
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 22c2f69..8eb4c9c 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -716,6 +716,8 @@
next(item for item in items if item.get('name')
== bom_item.get('item_code'))
)
+
+ bom_item.parent_bom_qty = bom_doc.quantity
bom_item.expandable = 0 if bom_item.value in ('', None) else 1
return bom_items
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 048ce0d..b51420f 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -301,7 +301,6 @@
wo_list.extend(work_orders)
frappe.flags.mute_messages = False
-
if wo_list:
wo_list = ["""<a href="#Form/Work Order/%s" target="_blank">%s</a>""" % \
(p, p) for p in wo_list]
@@ -309,15 +308,16 @@
else :
msgprint(_("No Work Orders created"))
+
def make_work_order_for_sub_assembly_items(self, item):
work_orders = []
bom_data = {}
- get_sub_assembly_items(item.get("bom_no"), bom_data)
+ get_sub_assembly_items(item.get("bom_no"), bom_data, item.get("qty"))
for key, data in bom_data.items():
data.update({
- 'qty': data.get("stock_qty") * item.get("qty"),
+ 'qty': data.get("stock_qty"),
'production_plan': self.name,
'company': self.company,
'fg_warehouse': item.get("fg_warehouse"),
@@ -708,7 +708,7 @@
"description": item_details.get("description")
}
-def get_sub_assembly_items(bom_no, bom_data):
+def get_sub_assembly_items(bom_no, bom_data, qty):
data = get_children('BOM', parent = bom_no)
for d in data:
if d.expandable:
@@ -725,6 +725,6 @@
})
bom_item = bom_data.get(key)
- bom_item["stock_qty"] += d.stock_qty
+ bom_item["stock_qty"] += ((d.stock_qty * qty) / d.parent_bom_qty)
- get_sub_assembly_items(bom_item.get("bom_no"), bom_data)
+ get_sub_assembly_items(bom_item.get("bom_no"), bom_data, bom_item["stock_qty"])