Upgrade BOM Stock Report base with Qty to Produce (#15939)

This commit is contained in:
Stavros Anastasiadis 2018-11-13 07:47:41 +02:00 committed by Nabin Hait
parent 89974b221d
commit a695dad525
2 changed files with 33 additions and 4 deletions

View File

@ -16,6 +16,22 @@ frappe.query_reports["BOM Stock Report"] = {
"fieldname": "show_exploded_view",
"label": __("Show exploded view"),
"fieldtype": "Check"
}, {
"fieldname": "qty_to_produce",
"label": __("Quantity to Produce"),
"fieldtype": "Int",
"default": "1"
},
],
"formatter": function(value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data);
if (column.id == "Item"){
if (data["Enough Parts to Build"] > 0){
value = `<a style='color:green' href="#Form/Item/${data['Item']}" data-doctype="Item">${data['Item']}</a>`
} else {
value = `<a style='color:red' href="#Form/Item/${data['Item']}" data-doctype="Item">${data['Item']}</a>`
}
}
]
return value
}
}

View File

@ -7,6 +7,7 @@ from frappe import _
def execute(filters=None):
if not filters: filters = {}
columns = get_columns()
data = get_bom_stock(filters)
@ -18,6 +19,7 @@ def get_columns():
columns = [
_("Item") + ":Link/Item:150",
_("Description") + "::500",
_("Qty per BOM Line") + ":Float:100",
_("Required Qty") + ":Float:100",
_("In Stock Qty") + ":Float:100",
_("Enough Parts to Build") + ":Float:200",
@ -32,6 +34,10 @@ def get_bom_stock(filters):
table = "`tabBOM Item`"
qty_field = "qty"
qty_to_produce = filters.get("qty_to_produce", 1)
if int(qty_to_produce) <= 0:
frappe.throw(_("Quantity to Produce can not be less than Zero"))
if filters.get("show_exploded_view"):
table = "`tabBOM Explosion Item`"
qty_field = "stock_qty"
@ -50,11 +56,12 @@ def get_bom_stock(filters):
return frappe.db.sql("""
SELECT
bom_item.item_code ,
bom_item.item_code,
bom_item.description ,
bom_item.{qty_field},
bom_item.{qty_field} * {qty_to_produce},
sum(ledger.actual_qty) as actual_qty,
sum(FLOOR(ledger.actual_qty / bom_item.{qty_field}))as to_build
sum(FLOOR(ledger.actual_qty / (bom_item.{qty_field} * {qty_to_produce})))
FROM
{table} AS bom_item
LEFT JOIN `tabBin` AS ledger
@ -63,4 +70,10 @@ def get_bom_stock(filters):
WHERE
bom_item.parent = '{bom}' and bom_item.parenttype='BOM'
GROUP BY bom_item.item_code""".format(qty_field=qty_field, table=table, conditions=conditions, bom=bom))
GROUP BY bom_item.item_code""".format(
qty_field=qty_field,
table=table,
conditions=conditions,
bom=bom,
qty_to_produce=qty_to_produce or 1)
)