From cc431716edece562d5cac01c77cae6dc55a412b4 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 22 Jul 2015 12:13:47 +0530 Subject: [PATCH 1/2] Fetch Template Bom if no BOM is set against Item Variant in Production Order --- .../doctype/production_order/production_order.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 26af40a4414..93ce5e16f64 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -335,12 +335,15 @@ def get_item_details(item): res = frappe.db.sql("""select stock_uom, description from `tabItem` where (ifnull(end_of_life, "0000-00-00")="0000-00-00" or end_of_life > now()) and name=%s""", item, as_dict=1) - if not res: return {} res = res[0] res["bom_no"] = frappe.db.get_value("BOM", filters={"item": item, "is_default": 1}) + if not res["bom_no"]: + variant_of= frappe.db.get_value("Item", item, "variant_of") + if variant_of: + res["bom_no"] = frappe.db.get_value("BOM", filters={"item": variant_of, "is_default": 1}) return res @frappe.whitelist() From 8b48ceab8c5b830a674a1f440d0394eb84444bd7 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 22 Jul 2015 12:42:21 +0530 Subject: [PATCH 2/2] Removed logic for get_item_details in Production Planning Tool, Used get_item_details function of Production Order instead --- .../production_planning_tool.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) 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 86a14d8c213..271abac10e5 100644 --- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py +++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py @@ -9,6 +9,7 @@ from frappe import msgprint, _ from frappe.model.document import Document from erpnext.manufacturing.doctype.bom.bom import validate_bom_no +from erpnext.manufacturing.doctype.production_order.production_order import get_item_details class ProductionPlanningTool(Document): def __init__(self, arg1, arg2=None): @@ -27,16 +28,7 @@ class ProductionPlanningTool(Document): return ret def get_item_details(self, item_code): - """ Pull other item details from item master""" - - item = frappe.db.sql("""select description, stock_uom, default_bom - from `tabItem` where name = %s""", item_code, as_dict =1) - ret = { - 'description' : item and item[0]['description'], - 'stock_uom' : item and item[0]['stock_uom'], - 'bom_no' : item and item[0]['default_bom'] - } - return ret + return get_item_details(item_code) def clear_so_table(self): self.set('sales_orders', []) @@ -142,15 +134,14 @@ class ProductionPlanningTool(Document): self.clear_item_table() for p in items: - item_details = frappe.db.sql("""select description, stock_uom, default_bom - from tabItem where name=%s""", p['item_code']) + item_details = get_item_details(p['item_code']) pi = self.append('items', {}) pi.sales_order = p['parent'] pi.warehouse = p['warehouse'] pi.item_code = p['item_code'] - pi.description = item_details and item_details[0][0] or '' - pi.stock_uom = item_details and item_details[0][1] or '' - pi.bom_no = item_details and item_details[0][2] or '' + pi.description = item_details and item_details.description or '' + pi.stock_uom = item_details and item_details.stock_uom or '' + pi.bom_no = item_details and item_details.bom_no or '' pi.so_pending_qty = flt(p['pending_qty']) pi.planned_qty = flt(p['pending_qty'])