Fixed code issues
Also changed qty to Quantity left to build
This commit is contained in:
parent
05dca985e6
commit
fc41bb6afd
@ -7,7 +7,7 @@ import frappe
|
||||
|
||||
def execute(filters=None):
|
||||
prod_list = get_production_orders()
|
||||
data = get_item_list( prod_list, filters)
|
||||
data = get_item_list(prod_list, filters)
|
||||
columns = get_columns()
|
||||
return columns, data
|
||||
|
||||
@ -17,49 +17,49 @@ def get_item_list(prod_list, filters):
|
||||
low_price_data = []
|
||||
low_supplier = []
|
||||
|
||||
# Get the default supplier of suppliers
|
||||
#Add a row for each item/qty
|
||||
for root in prod_list:
|
||||
bom = frappe.db.get_value("Production Order", root.name,"bom_no")
|
||||
warehouse = frappe.db.get_value("Production Order", root.name,"source_warehouse")
|
||||
warehouse = "Stores - VMI"
|
||||
for prod_order in prod_list:
|
||||
bom = frappe.db.get_value("Production Order", prod_order.name, "bom_no")
|
||||
warehouse = frappe.db.get_value("Production Order", prod_order.name, "source_warehouse")
|
||||
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
|
||||
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
|
||||
`tabBOM Item` AS bom_item
|
||||
LEFT JOIN `tabBin` AS ledger
|
||||
ON bom_item.item_code = ledger.item_code AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s)
|
||||
LEFT JOIN `tabUOM Conversion Detail` AS conf_item
|
||||
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
|
||||
ON bom_item.item_code = ledger.item_code
|
||||
AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s)
|
||||
WHERE
|
||||
bom_item.parent = %(bom)s
|
||||
GROUP BY
|
||||
bom_item.item_code""", {"bom": bom, "warehouse": warehouse, "filterhouse": filters.warehouse}, as_dict=1)
|
||||
stock_qty = 0
|
||||
count = 0
|
||||
buildable_qty = qty
|
||||
for item in item_list:
|
||||
count = count + 1
|
||||
if item.build_qty >= qty:
|
||||
if item.build_qty >= (qty-produced_value):
|
||||
stock_qty = stock_qty + 1
|
||||
elif buildable_qty > item.build_qty:
|
||||
buidable_qty = item.build_qty
|
||||
|
||||
if count == stock_qty:
|
||||
build = "Y"
|
||||
else:
|
||||
build = "N"
|
||||
|
||||
row = frappe._dict({
|
||||
"production_order": root.name,
|
||||
"status": root.status,
|
||||
"production_order": prod_order.name,
|
||||
"status": prod_order.status,
|
||||
"req_items": cint(count),
|
||||
"instock": stock_qty,
|
||||
"description": desc,
|
||||
"bom_no": bom,
|
||||
"qty": qty,
|
||||
"buildable_qty": buildable_qty,
|
||||
"ready_to_build": build
|
||||
})
|
||||
|
||||
@ -69,16 +69,7 @@ def get_item_list(prod_list, filters):
|
||||
|
||||
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')
|
||||
#prod_list.sort(reverse=False)
|
||||
|
||||
#for po in prod_list:
|
||||
#out.append(po)
|
||||
|
||||
return out
|
||||
|
||||
def get_columns():
|
||||
@ -88,43 +79,43 @@ def get_columns():
|
||||
"fieldtype": "Link",
|
||||
"options": "Production Order",
|
||||
"width": 110
|
||||
},{
|
||||
}, {
|
||||
"fieldname": "bom_no",
|
||||
"label": "BOM",
|
||||
"fieldtype": "Link",
|
||||
"options": "BOM",
|
||||
"width": 130
|
||||
},{
|
||||
}, {
|
||||
"fieldname": "description",
|
||||
"label": "Description",
|
||||
"fieldtype": "Data",
|
||||
"options": "",
|
||||
"width": 250
|
||||
},{
|
||||
}, {
|
||||
"fieldname": "qty",
|
||||
"label": "Qty to Build",
|
||||
"fieldtype": "Data",
|
||||
"options": "",
|
||||
"width": 110
|
||||
},{
|
||||
}, {
|
||||
"fieldname": "status",
|
||||
"label": "Status",
|
||||
"fieldtype": "Data",
|
||||
"options": "",
|
||||
"width": 110
|
||||
},{
|
||||
}, {
|
||||
"fieldname": "req_items",
|
||||
"label": "# of Required Items",
|
||||
"fieldtype": "Data",
|
||||
"options": "",
|
||||
"width": 135
|
||||
},{
|
||||
}, {
|
||||
"fieldname": "instock",
|
||||
"label": "# of In Stock Items",
|
||||
"fieldtype": "Data",
|
||||
"options": "",
|
||||
"width": 135
|
||||
}, {
|
||||
}, {
|
||||
"fieldname": "ready_to_build",
|
||||
"label": "Can Start?",
|
||||
"fieldtype": "Data",
|
||||
|
Loading…
x
Reference in New Issue
Block a user