Exploded view for BOM Stock Report (#12506)

* Multilevel BOM Stock Report prototype

* Rechristened multilevel to exploded view

* Removed trailing whitespace in line 16. Replaced spaces with tabs for indentation

* Used BOM Explosion item in query for exploded view

* Removed trailing whitespaces for Codacy compliance
This commit is contained in:
Gaurav Naik 2018-01-17 16:12:55 +05:30 committed by Nabin Hait
parent d8b4c8bd5b
commit dc0db3a652
2 changed files with 53 additions and 40 deletions

View File

@ -12,6 +12,10 @@ frappe.query_reports["BOM Stock Report"] = {
"fieldtype": "Link", "fieldtype": "Link",
"options": "Warehouse", "options": "Warehouse",
"reqd": 1 "reqd": 1
}, {
"fieldname": "show_exploded_view",
"label": __("Show exploded view"),
"fieldtype": "Check"
} }
] ]
} }

View File

@ -8,7 +8,9 @@ from frappe import _
def execute(filters=None): def execute(filters=None):
if not filters: filters = {} if not filters: filters = {}
columns = get_columns() columns = get_columns()
data = get_bom_stock(filters) data = get_bom_stock(filters)
return columns, data return columns, data
def get_columns(): def get_columns():
@ -27,6 +29,13 @@ def get_bom_stock(filters):
conditions = "" conditions = ""
bom = filters.get("bom") bom = filters.get("bom")
table = "`tabBOM Item`"
qty_field = "qty"
if filters.get("show_exploded_view"):
table = "`tabBOM Explosion Item`"
qty_field = "stock_qty"
if filters.get("warehouse"): if filters.get("warehouse"):
warehouse_details = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1) warehouse_details = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1)
if warehouse_details: if warehouse_details:
@ -43,15 +52,15 @@ def get_bom_stock(filters):
SELECT SELECT
bom_item.item_code , bom_item.item_code ,
bom_item.description , bom_item.description ,
bom_item.qty, bom_item.{qty_field},
sum(ledger.actual_qty) as actual_qty, sum(ledger.actual_qty) as actual_qty,
sum(FLOOR(ledger.actual_qty /bom_item.qty))as to_build sum(FLOOR(ledger.actual_qty / bom_item.{qty_field}))as to_build
FROM FROM
`tabBOM Item` AS bom_item {table} 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
%s {conditions}
WHERE WHERE
bom_item.parent = '%s' and bom_item.parenttype='BOM' bom_item.parent = '{bom}' and bom_item.parenttype='BOM'
GROUP BY bom_item.item_code""" % (conditions, bom)) GROUP BY bom_item.item_code""".format(qty_field=qty_field, table=table, conditions=conditions, bom=bom))