Upgrade BOM Stock Report base with Qty to Produce (#15939)
diff --git a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js
index 049a822..2ac6fa0 100644
--- a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js
+++ b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.js
@@ -16,6 +16,22 @@
"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
+ }
}
diff --git a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py
index 3236839..ec36720 100644
--- a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py
+++ b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py
@@ -7,6 +7,7 @@
def execute(filters=None):
if not filters: filters = {}
+
columns = get_columns()
data = get_bom_stock(filters)
@@ -18,6 +19,7 @@
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 @@
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 @@
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 @@
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)
+ )