Merge pull request #7791 from nabinhait/pro_order_stock_qty

Build Qty considering quantity for which bom is created
This commit is contained in:
Nabin Hait 2017-02-21 09:58:13 +05:30 committed by GitHub
commit d5442b5544

View File

@ -2,7 +2,7 @@
# For license information, please see license.txt # For license information, please see license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
from frappe.utils import flt, cint from frappe.utils import cint
import frappe import frappe
def execute(filters=None): def execute(filters=None):
@ -14,39 +14,39 @@ def execute(filters=None):
def get_item_list(prod_list, filters): def get_item_list(prod_list, filters):
out = [] out = []
low_price_data = []
low_supplier = []
#Add a row for each item/qty #Add a row for each item/qty
for prod_order in prod_list: for prod_order in prod_list:
bom = frappe.db.get_value("Production Order", prod_order.name, "bom_no") prod_details = frappe.db.get_value("Production Order", prod_order.name,
warehouse = frappe.db.get_value("Production Order", prod_order.name, "source_warehouse") ["bom_no", "source_warehouse", "qty", "produced_qty"], as_dict=1)
desc = frappe.db.get_value("BOM", bom, "description")
qty = frappe.db.get_value("Production Order", prod_order.name, "qty") desc = frappe.db.get_value("BOM", prod_details.bom_no, "description")
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,
ifnull(ledger.actual_qty/bom_item.qty,0) as build_qty ifnull(ledger.actual_qty*bom.quantity/bom_item.qty,0) as build_qty
FROM FROM
`tabBOM Item` AS bom_item `tabBOM` as bom, `tabBOM Item` AS bom_item
LEFT JOIN `tabBin` AS ledger LEFT JOIN `tabBin` AS ledger
ON bom_item.item_code = ledger.item_code ON bom_item.item_code = ledger.item_code
AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s) AND ledger.warehouse = ifnull(%(warehouse)s,%(filterhouse)s)
WHERE WHERE
bom_item.parent = %(bom)s bom.name = bom_item.parent
and bom.name = %(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": prod_details.bom_no, "warehouse": prod_details.source_warehouse,
"filterhouse": filters.warehouse}, as_dict=1)
stock_qty = 0 stock_qty = 0
count = 0 count = 0
buildable_qty = qty buildable_qty = prod_details.qty
for item in item_list: for item in item_list:
count = count + 1 count = count + 1
if item.build_qty >= (qty-produced_value): if item.build_qty >= (prod_details.qty - prod_details.produced_qty):
stock_qty = stock_qty + 1 stock_qty = stock_qty + 1
elif buildable_qty >= item.build_qty: elif buildable_qty >= item.build_qty:
buildable_qty = item.build_qty buildable_qty = item.build_qty
if count == stock_qty: if count == stock_qty:
build = "Y" build = "Y"
else: else:
@ -58,8 +58,8 @@ def get_item_list(prod_list, filters):
"req_items": cint(count), "req_items": cint(count),
"instock": stock_qty, "instock": stock_qty,
"description": desc, "description": desc,
"bom_no": bom, "bom_no": prod_details.bom_no,
"qty": qty, "qty": prod_details.qty,
"buildable_qty": buildable_qty, "buildable_qty": buildable_qty,
"ready_to_build": build "ready_to_build": build
}) })