mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-20 03:47:11 +00:00
refactor(manufacturing): share the bin subquery in BOM Stock Analysis (#59121)
This commit is contained in:
@@ -322,31 +322,11 @@ def get_manufacturer_records():
|
||||
def get_producible_fg_items(filters):
|
||||
BOM_ITEM = frappe.qb.DocType("BOM Item")
|
||||
BOM = frappe.qb.DocType("BOM")
|
||||
BIN = frappe.qb.DocType("Bin")
|
||||
WH = frappe.qb.DocType("Warehouse")
|
||||
|
||||
warehouse = filters.get("warehouse")
|
||||
if not warehouse:
|
||||
if not filters.get("warehouse"):
|
||||
frappe.throw(_("Warehouse is required to get producible FG Items"))
|
||||
|
||||
warehouse_details = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"], as_dict=1)
|
||||
|
||||
if warehouse_details:
|
||||
bin_subquery = (
|
||||
frappe.qb.from_(BIN)
|
||||
.join(WH)
|
||||
.on(BIN.warehouse == WH.name)
|
||||
.select(BIN.item_code, Sum(BIN.actual_qty).as_("actual_qty"))
|
||||
.where((WH.lft >= warehouse_details.lft) & (WH.rgt <= warehouse_details.rgt))
|
||||
.groupby(BIN.item_code)
|
||||
)
|
||||
else:
|
||||
bin_subquery = (
|
||||
frappe.qb.from_(BIN)
|
||||
.select(BIN.item_code, Sum(BIN.actual_qty).as_("actual_qty"))
|
||||
.where(BIN.warehouse == warehouse)
|
||||
.groupby(BIN.item_code)
|
||||
)
|
||||
bin_subquery = get_stock_qty_by_item(filters).as_("stock_qty")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(BOM_ITEM)
|
||||
|
||||
Reference in New Issue
Block a user