def test_get_items_list(self): from erpnext.manufacturing.doctype.bom.bom import get_bom_items self.assertEquals( len( get_bom_items(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=1)), 3)
def execute(filters=None): if not filters: filters = {} conditions, filters = get_conditions(filters) columns = get_columns(filters) data = [] if not conditions: return columns, data quotation_list = get_quotation(conditions, filters) if not quotation_list: return columns, data project = quotation_list[0]["project"] company = quotation_list[0]["company"] # title = quotation_list[0]["title"] # name = quotation_list[0]["name"] # row = [name,title,project,"",""] # data.append(row) quotation_names = "" for i, quotation in enumerate(quotation_list): quotation_names += str(quotation.name) if not i == len(quotation_list) - 1: quotation_names += "," headers = ["header1", "header2", "header3"] doctype = filters.get("format") if doctype == "Sales Order": item_list = frappe.db.sql( "select item_code,item_name,description,item_group,stock_uom,warehouse, SUM(qty) AS qty,brand,actual_qty from `tabSales Order Item` t2 where t2.parent in (%s) GROUP BY item_code,warehouse", quotation_names, as_dict=1) elif doctype == "Quotation": item_list = frappe.db.sql( "select item_code,item_name,description,item_group,stock_uom,warehouse,SUM(qty) AS qty,brand,actual_qty from `tabQuotation Item` t2 where t2.parent in (%s) GROUP BY item_code,warehouse", quotation_names, as_dict=1) elif doctype == "Delivery Note": item_list = frappe.db.sql( "select item_code,item_name,description,item_group,stock_uom,warehouse,SUM(qty) AS qty,brand,actual_qty from `tabDelivery Note Item` t2 where t2.parent in (%s) GROUP BY item_code,warehouse", quotation_names, as_dict=1) all_bom_items = [] newlist = [] for i, item in enumerate(item_list): if not item.item_group.lower() in headers: newlist.append(item) for item in newlist: from frappe.utils import strip_html_tags item["description"] = strip_html_tags(item["description"]) item["description"] = item["description"][:55] + ( item["description"][55:] and '..') if filters.get("bom_only") == "Without BOM": actual_qty = get_actual_qty(item["item_code"]) if doctype == "Sales Order": row = [ item["item_code"], item["item_name"], item["description"], item["stock_uom"], item["qty"], actual_qty ] else: row = [ item["item_code"], item["item_name"], item["description"], item["stock_uom"], item["qty"], actual_qty ] data.append(row) elif filters.get("bom_only") == "With BOM": bom = get_default_bom(item["item_code"], project) actual_qty = get_actual_qty(item["item_code"]) if doctype == "Sales Order": row = [ item["item_code"], item["item_name"], item["description"], item["stock_uom"], item["qty"], actual_qty ] else: row = [ item["item_code"], item["item_name"], item["description"], item["stock_uom"], item["qty"], actual_qty ] data.append(row) if bom: bomitems = get_bom_items(bom, company=company, qty=item["qty"]) if bomitems: row = ["", "---------", "", "", ""] data.append(row) for b in bomitems: actual_qty = get_actual_qty(b["item_code"]) row = [ b["item_code"], b["item_name"], b["description"], b["stock_uom"], b["qty"], actual_qty ] data.append(row) row = ["", "---------", "", "", ""] data.append(row) elif filters.get("bom_only") == "Consolidate BOM": bom = get_default_bom(item["item_code"], project) if bom: bomitems = get_bom_items(bom, company=company, qty=item["qty"]) for b in bomitems: actual_qty = get_actual_qty(b["item_code"]) new_bom_item = { 'item_code': b['item_code'], 'item_name': b["item_name"], 'description': b["description"], 'stock_uom': b["stock_uom"], 'qty': b["qty"], 'actual_qty': actual_qty } all_bom_items.append(new_bom_item) else: bom = get_default_bom(item["item_code"], project) if bom: actual_qty = get_actual_qty(item["item_code"]) if doctype == "Sales Order": row = [ item["item_code"], item["item_name"], item["description"], item["stock_uom"], item["qty"], actual_qty ] else: row = [ item["item_code"], item["item_name"], item["description"], item["stock_uom"], item["qty"], actual_qty ] data.append(row) bomitems = get_bom_items(bom, company=company, qty=item["qty"]) if bomitems: row = ["", "---------", "", "", ""] data.append(row) for b in bomitems: actual_qty = get_actual_qty(b["item_code"]) row = [ b["item_code"], b["item_name"], b["description"], b["stock_uom"], b["qty"], actual_qty ] data.append(row) row = ["", "---------", "", "", ""] data.append(row) if filters.get("bom_only") == "Consolidate BOM": merged_bom_items = merge(all_bom_items) for b in merged_bom_items: d = merged_bom_items[b] row = [ d["item_code"], d["item_name"], d["description"], d["stock_uom"], d["qty"], d["actual_qty"] ] data.append(row) return columns, data
def test_get_items_list(self): from erpnext.manufacturing.doctype.bom.bom import get_bom_items self.assertEquals(len(get_bom_items(bom=get_default_bom())), 3)
def get_data(filters,quotation_names): if filters.get("format") == "SO": query = 'select item_code,item_name,description,item_group,stock_uom,SUM(qty) AS qty, brand, SUM(delivered_qty) AS delivered_qty from `tabSales Order Item` where parent IN (%s) GROUP BY item_code' % quotation_names else: query = 'select item_code,item_name,description,item_group,stock_uom,SUM(qty) AS qty, brand from `tabQuotation Item` where parent IN (%s) GROUP BY item_code' % quotation_names item_list = frappe.db.sql(query, as_dict = 1) project = filters["project"] newlist = [] data = [] headers = ["header1","header2","header3"] for i,item in enumerate(item_list): if not item.item_group.lower() in headers: newlist.append(item) bomitems = {} for item in newlist: from frappe.utils import strip_html_tags item["description"] = strip_html_tags(item["description"]) item["description"] = item["description"][:55] + (item["description"][55:] and '..') if filters.get("bom_only") == "Without BOM": if filters.get("format") == "SO": stock_details = frappe.db.sql("select actual_qty from `tabBin` where item_code = (%s)", item["item_code"], as_dict = 1) actual_qty = 0 if stock_details: actual_qty =flt(stock_details[0]) row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"], item.delivered_qty, actual_qty] else: row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"]] data.append(row) else: from erpnext.manufacturing.doctype.bom.bom import get_bom_items bom = frappe.db.get_value("BOM", filters={"item": item["item_code"], "project": project}) or frappe.db.get_value("BOM", filters={"item": item["item_code"], "is_default": 1}) frappe.errprint(bom) if bom: if filters.get("format") == "SO": stock_details = frappe.db.sql("select actual_qty from `tabBin` where item_code = (%s)", item["item_code"], as_dict = 1) actual_qty = 0 if stock_details: actual_qty =flt(stock_details[0]) row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"], item.delivered_qty, actual_qty] bomitems = get_bom_items(bom, company="Al Maarifa Lab Supplies LLC",qty = item["qty"]) else: row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"]] bomitems = get_bom_items(bom, company="Al Maarifa Lab Supplies LLC",qty = item["qty"]) data.append(row) if bomitems: row = [item["item_code"] + " BOM","", "","",""] data.append(row) for b in bomitems: row = [b["item_code"],b["item_name"], b["description"],b["stock_uom"],b["qty"]] data.append(row) row = ["","", "","",""] data.append(row) return data
def test_get_items_list(self): from erpnext.manufacturing.doctype.bom.bom import get_bom_items default_bom = frappe.db.get_value("BOM", {"item":"_Test FG Item 2", "is_default": 1}) self.assertEquals(len(get_bom_items(bom=default_bom)), 3)
def test_get_items_list(self): from erpnext.manufacturing.doctype.bom.bom import get_bom_items self.assertEquals(len(get_bom_items(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=1)), 3)
def execute(filters=None): if not filters: filters = {} conditions, filters = get_conditions(filters) columns = get_columns(filters) data = [] if not conditions: return columns, data quotation_list = get_quotation(conditions, filters) if not quotation_list: return columns, data project = quotation_list[0]["project"] # title = quotation_list[0]["title"] # name = quotation_list[0]["name"] # row = [name,title,project,"",""] # data.append(row) quotation_names = "" for i, quotation in enumerate(quotation_list): quotation_names += str(quotation.name) if not i == len(quotation_list)-1: quotation_names += "," headers = ["header1","header2","header3"] if filters.get("format") == "Sales Order": item_list = frappe.db.sql("select item_code,item_name,description,item_group,stock_uom, SUM(qty) AS qty,brand,SUM(delivered_qty) AS delivered_qty from `tabSales Order Item` t2 where t2.parent in (%s) GROUP BY item_code", quotation_names, as_dict = 1) else: item_list = frappe.db.sql("select item_code,item_name,description,item_group,stock_uom,SUM(qty) AS qty,brand from `tabQuotation Item` t2 where t2.parent in (%s) GROUP BY item_code", quotation_names, as_dict = 1) newlist = [] for i,item in enumerate(item_list): if not item.item_group.lower() in headers: newlist.append(item) bomitems = {} for item in newlist: from frappe.utils import strip_html_tags item["description"] = strip_html_tags(item["description"]) item["description"] = item["description"][:55] + (item["description"][55:] and '..') if filters.get("bom_only") == "Without BOM": if filters.get("format") == "Sales Order": stock_details = frappe.db.sql("select actual_qty from `tabBin` where item_code = (%s)", item["item_code"], as_dict = 1) actual_qty = 0 if stock_details: actual_qty =flt(stock_details[0]) row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"], item.delivered_qty, actual_qty] else: row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"]] data.append(row) else: from erpnext.manufacturing.doctype.bom.bom import get_bom_items bom = frappe.db.get_value("BOM", filters={"item": item["item_code"], "project": project}) or frappe.db.get_value("BOM", filters={"item": item["item_code"], "is_default": 1}) frappe.errprint(bom) if bom: if filters.get("format") == "Sales Order": stock_details = frappe.db.sql("select actual_qty from `tabBin` where item_code = (%s)", item["item_code"], as_dict = 1) actual_qty = 0 if stock_details: actual_qty =flt(stock_details[0]) row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"], item.delivered_qty, actual_qty] bomitems = get_bom_items(bom, company="Al Maarifa Lab Supplies LLC",qty = item["qty"]) else: row = [item["item_code"],item["item_name"], item["description"],item["stock_uom"],item["qty"]] bomitems = get_bom_items(bom, company="Al Maarifa Lab Supplies LLC",qty = item["qty"]) data.append(row) if bomitems: row = [item["item_code"] + " BOM","", "","",""] data.append(row) for b in bomitems: row = [b["item_code"],b["item_name"], b["description"],b["stock_uom"],b["qty"]] data.append(row) row = ["","", "","",""] data.append(row) return columns, data