diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py index aaa0e95ec08..e4cee4b4de3 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -363,9 +363,17 @@ class ProductionPlanningTool(Document): bom_wise_item_details[d.item_code] = d if include_sublevel: if (d.default_material_request_type == "Purchase" and d.is_sub_contracted \ - and supply_subs) or (d.default_material_request_type == "Manufacture"): - self.get_subitems(bom_wise_item_details,d.default_bom, \ - d.qty, include_sublevel, only_raw, supply_subs) + and supply_subs) or (d.default_material_request_type == "Manufacture"): + my_qty = 0 + if self.create_material_requests_for_all_required_qty: + my_qty = d.qty + elif (bom_wise_item_details[d.item_code].qty - d.qty) < self.get_item_projected_qty(d.item_code): + my_qty = bom_wise_item_details[d.item_code].qty - self.get_item_projected_qty(d.item_code) + else: + my_qty = d.qty + if my_qty > 0: + self.get_subitems(bom_wise_item_details,d.default_bom, \ + my_qty, include_sublevel, only_raw, supply_subs) return bom_wise_item_details def make_items_dict(self, item_list): @@ -387,6 +395,8 @@ class ProductionPlanningTool(Document): flt(w.ordered_qty), flt(w.actual_qty)]) if item_qty: item_list.append(['', '', '', '', 'Total', i_qty, o_qty, a_qty]) + else: + item_list.append(['', '', '', '', 'Total', 0, 0, 0]) return item_list @@ -449,6 +459,13 @@ class ProductionPlanningTool(Document): return items_to_be_requested + def get_item_projected_qty(self,item): + item_projected_qty = frappe.db.sql("""select ifnull(sum(projected_qty),0) as qty from `tabBin` + where item_code = %(item_code)s and warehouse=%(warehouse)s""", \ + {"item_code":item, "warehouse": self.purchase_request_for_warehouse},as_dict=1) + #frappe.msgprint(item_projected_qty) + return item_projected_qty[0].qty + def get_projected_qty(self): items = self.item_dict.keys() item_projected_qty = frappe.db.sql("""select item_code, sum(projected_qty)