Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade BOM Stock Report base with Qty to Produce #15697

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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
}
}
Expand Up @@ -7,6 +7,7 @@

def execute(filters=None):
if not filters: filters = {}

columns = get_columns()

data = get_bom_stock(filters)
Expand All @@ -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",
Expand All @@ -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"
Expand All @@ -43,18 +49,19 @@ def get_bom_stock(filters):
where wh.lft >= %s and wh.rgt <= %s and ledger.warehouse = wh.name)" % (warehouse_details.lft,
warehouse_details.rgt)
else:
conditions += " and ledger.warehouse = %s" % frappe.db.escape(filters.get("warehouse"))
conditions += " and ledger.warehouse = '%s'" % frappe.db.escape(filters.get("warehouse"))

else:
conditions += ""

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
Expand All @@ -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)
)