From bb736248a29151f736543c09889a1fa6d5894e09 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 11 Sep 2019 10:20:49 +0530 Subject: [PATCH] fix: incorrect qty calculation in the production plan fopr the sub assembely work orders (#18970) --- erpnext/manufacturing/doctype/bom/bom.py | 2 ++ .../doctype/production_plan/production_plan.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 22c2f694f5..8eb4c9c28c 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -716,6 +716,8 @@ def get_children(doctype, parent=None, is_root=False, **filters): 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 048ce0d6ef..b51420ffdb 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -301,7 +301,6 @@ class ProductionPlan(Document): wo_list.extend(work_orders) frappe.flags.mute_messages = False - if wo_list: wo_list = ["""%s""" % \ (p, p) for p in wo_list] @@ -309,15 +308,16 @@ class ProductionPlan(Document): 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 @@ def get_item_data(item_code): "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 @@ def get_sub_assembly_items(bom_no, bom_data): }) 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"])