diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json index 8438e07ba7..8d844cda7e 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json @@ -698,6 +698,32 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "description": "If checked, Will include non-stock items in the Material Requests.", + "fieldname": "create_material_requests_non_stock_request", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Include non-stock items", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -823,4 +849,4 @@ "read_only_onload": 0, "sort_order": "ASC", "track_seen": 0 -} \ No newline at end of file +} 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 fd28b547a9..8521b5e8d6 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -307,7 +307,7 @@ class ProductionPlanningTool(Document): self.get_raw_materials(bom_dict) return self.get_csv() - def get_raw_materials(self, bom_dict): + def get_raw_materials(self, bom_dict,non_stock_item=0): """ Get raw materials considering sub-assembly items { "item_code": [qty_required, description, stock_uom, min_order_qty] @@ -326,7 +326,7 @@ class ProductionPlanningTool(Document): from `tabBOM Explosion Item` fb, `tabBOM` bom, `tabItem` item where bom.name = fb.parent and item.name = fb.item_code and (item.is_sub_contracted_item = 0 or ifnull(item.default_bom, "")="") - and item.is_stock_item = 1 + """ + ("and item.is_stock_item = 1","")[non_stock_item] + """ and fb.docstatus<2 and bom.name=%(bom)s group by fb.item_code, fb.stock_uom""", {"bom":bom}, as_dict=1): bom_wise_item_details.setdefault(d.item_code, d) @@ -334,7 +334,7 @@ class ProductionPlanningTool(Document): # Get all raw materials considering SA items as raw materials, # so no childs of SA items bom_wise_item_details = self.get_subitems(bom_wise_item_details, bom,1, \ - self.use_multi_level_bom,self.only_raw_materials, self.include_subcontracted) + self.use_multi_level_bom,self.only_raw_materials, self.include_subcontracted,non_stock_item) for item, item_details in bom_wise_item_details.items(): for so_qty in so_wise_qty: @@ -343,14 +343,14 @@ class ProductionPlanningTool(Document): self.make_items_dict(item_list) - def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs): + def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs,non_stock_item=0): for d in frappe.db.sql("""select bom_item.item_code, default_material_request_type, ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty, item.is_sub_contracted_item as is_sub_contracted, item.default_bom as default_bom from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item where bom.name = bom_item.parent and bom.name = %(bom)s and bom_item.docstatus < 2 and bom_item.item_code = item.name - and item.is_stock_item = 1 + """ + ("and item.is_stock_item = 1","")[non_stock_item] + """ group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1): if (d.default_material_request_type == "Purchase" and not (d.is_sub_contracted \ and only_raw and include_sublevel)) or (d.default_material_request_type == \ @@ -399,7 +399,7 @@ class ProductionPlanningTool(Document): frappe.throw(_("Please enter Warehouse for which Material Request will be raised")) bom_dict = self.get_so_wise_planned_qty() - self.get_raw_materials(bom_dict) + self.get_raw_materials(bom_dict,self.create_material_requests_non_stock_request) if self.item_dict: self.create_material_request()