Fixed code issues

Also changed qty to Quantity left to build
This commit is contained in:
bcornwellmott 2017-02-09 20:37:11 -08:00 committed by GitHub
parent 05dca985e6
commit fc41bb6afd

View File

@ -7,7 +7,7 @@ import frappe
def execute(filters=None): def execute(filters=None):
prod_list = get_production_orders() prod_list = get_production_orders()
data = get_item_list( prod_list, filters) data = get_item_list(prod_list, filters)
columns = get_columns() columns = get_columns()
return columns, data return columns, data
@ -17,49 +17,49 @@ def get_item_list(prod_list, filters):
low_price_data = [] low_price_data = []
low_supplier = [] low_supplier = []
# Get the default supplier of suppliers
#Add a row for each item/qty #Add a row for each item/qty
for root in prod_list: for prod_order in prod_list:
bom = frappe.db.get_value("Production Order", root.name,"bom_no") bom = frappe.db.get_value("Production Order", prod_order.name, "bom_no")
warehouse = frappe.db.get_value("Production Order", root.name,"source_warehouse") warehouse = frappe.db.get_value("Production Order", prod_order.name, "source_warehouse")
warehouse = "Stores - VMI"
desc = frappe.db.get_value("BOM", bom, "description") desc = frappe.db.get_value("BOM", bom, "description")
qty = frappe.db.get_value("Production Order", root.name,"qty") qty = frappe.db.get_value("Production Order", prod_order.name, "qty")
produced_value = frappe.db.get_value("Production Order", prod_order.name, "produced_qty")
item_list = frappe.db.sql("""SELECT item_list = frappe.db.sql("""SELECT
bom_item.item_code as item_code, bom_item.item_code as item_code,
SUM(ifnull(ledger.actual_qty * conf_ledger.conversion_factor,0))/(bom_item.qty * conf_item.conversion_factor) as build_qty ifnull(ledger.actual_qty,0)/(bom_item.qty) as build_qty
FROM FROM
`tabBOM Item` AS bom_item `tabBOM Item` AS bom_item
LEFT JOIN `tabBin` AS ledger LEFT JOIN `tabBin` AS ledger
ON bom_item.item_code = ledger.item_code AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s) ON bom_item.item_code = ledger.item_code
LEFT JOIN `tabUOM Conversion Detail` AS conf_item AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s)
ON conf_item.parent = bom_item.item_code AND conf_item.uom = bom_item.stock_uom
LEFT JOIN `tabUOM Conversion Detail` AS conf_ledger
ON conf_ledger.parent = ledger.item_code AND conf_ledger.uom = ledger.stock_uom
WHERE WHERE
bom_item.parent = %(bom)s bom_item.parent = %(bom)s
GROUP BY GROUP BY
bom_item.item_code""", {"bom": bom, "warehouse": warehouse, "filterhouse": filters.warehouse}, as_dict=1) bom_item.item_code""", {"bom": bom, "warehouse": warehouse, "filterhouse": filters.warehouse}, as_dict=1)
stock_qty = 0 stock_qty = 0
count = 0 count = 0
buildable_qty = qty
for item in item_list: for item in item_list:
count = count + 1 count = count + 1
if item.build_qty >= qty: if item.build_qty >= (qty-produced_value):
stock_qty = stock_qty + 1 stock_qty = stock_qty + 1
elif buildable_qty > item.build_qty:
buidable_qty = item.build_qty
if count == stock_qty: if count == stock_qty:
build = "Y" build = "Y"
else: else:
build = "N" build = "N"
row = frappe._dict({ row = frappe._dict({
"production_order": root.name, "production_order": prod_order.name,
"status": root.status, "status": prod_order.status,
"req_items": cint(count), "req_items": cint(count),
"instock": stock_qty, "instock": stock_qty,
"description": desc, "description": desc,
"bom_no": bom, "bom_no": bom,
"qty": qty, "qty": qty,
"buildable_qty": buildable_qty,
"ready_to_build": build "ready_to_build": build
}) })
@ -69,16 +69,7 @@ def get_item_list(prod_list, filters):
def get_production_orders(): def get_production_orders():
#out = []
#prod_list = frappe.db.sql("""select name, status from `tabProduction Order` as prod where status != "Completed" and docstatus = 1""", {}, as_dict=1)
out = frappe.get_all("Production Order", filters={"docstatus": 1, "status": ( "!=","Completed")}, fields=["name","status"], order_by='name') out = frappe.get_all("Production Order", filters={"docstatus": 1, "status": ( "!=","Completed")}, fields=["name","status"], order_by='name')
#prod_list.sort(reverse=False)
#for po in prod_list:
#out.append(po)
return out return out
def get_columns(): def get_columns():
@ -88,43 +79,43 @@ def get_columns():
"fieldtype": "Link", "fieldtype": "Link",
"options": "Production Order", "options": "Production Order",
"width": 110 "width": 110
},{ }, {
"fieldname": "bom_no", "fieldname": "bom_no",
"label": "BOM", "label": "BOM",
"fieldtype": "Link", "fieldtype": "Link",
"options": "BOM", "options": "BOM",
"width": 130 "width": 130
},{ }, {
"fieldname": "description", "fieldname": "description",
"label": "Description", "label": "Description",
"fieldtype": "Data", "fieldtype": "Data",
"options": "", "options": "",
"width": 250 "width": 250
},{ }, {
"fieldname": "qty", "fieldname": "qty",
"label": "Qty to Build", "label": "Qty to Build",
"fieldtype": "Data", "fieldtype": "Data",
"options": "", "options": "",
"width": 110 "width": 110
},{ }, {
"fieldname": "status", "fieldname": "status",
"label": "Status", "label": "Status",
"fieldtype": "Data", "fieldtype": "Data",
"options": "", "options": "",
"width": 110 "width": 110
},{ }, {
"fieldname": "req_items", "fieldname": "req_items",
"label": "# of Required Items", "label": "# of Required Items",
"fieldtype": "Data", "fieldtype": "Data",
"options": "", "options": "",
"width": 135 "width": 135
},{ }, {
"fieldname": "instock", "fieldname": "instock",
"label": "# of In Stock Items", "label": "# of In Stock Items",
"fieldtype": "Data", "fieldtype": "Data",
"options": "", "options": "",
"width": 135 "width": 135
}, { }, {
"fieldname": "ready_to_build", "fieldname": "ready_to_build",
"label": "Can Start?", "label": "Can Start?",
"fieldtype": "Data", "fieldtype": "Data",