Merge pull request #18186 from bhavishyasharma/fix-bom-item-with-operation
fix: BOM Item with Operation
This commit is contained in:
@@ -516,10 +516,14 @@ class BOM(WebsiteGenerator):
|
||||
return erpnext.get_company_currency(self.company)
|
||||
|
||||
def add_to_cur_exploded_items(self, args):
|
||||
if self.cur_exploded_items.get(args.item_code):
|
||||
self.cur_exploded_items[args.item_code]["stock_qty"] += args.stock_qty
|
||||
key = (args.item_code)
|
||||
if args.operation:
|
||||
key = (args.item_code, args.operation)
|
||||
|
||||
if key in self.cur_exploded_items:
|
||||
self.cur_exploded_items[key]["stock_qty"] += args.stock_qty
|
||||
else:
|
||||
self.cur_exploded_items[args.item_code] = args
|
||||
self.cur_exploded_items[key] = args
|
||||
|
||||
def get_child_exploded_items(self, bom_no, stock_qty):
|
||||
""" Add all items from Flat BOM of child BOM"""
|
||||
@@ -609,7 +613,7 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite
|
||||
and bom.name = %(bom)s
|
||||
and item.is_stock_item in (1, {is_stock_item})
|
||||
{where_conditions}
|
||||
group by item_code, stock_uom
|
||||
group by item_code, stock_uom {groupby_columns}
|
||||
order by idx"""
|
||||
|
||||
is_stock_item = 0 if include_non_stock_items else 1
|
||||
@@ -619,23 +623,29 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite
|
||||
is_stock_item=is_stock_item,
|
||||
qty_field="stock_qty",
|
||||
select_columns = """, bom_item.source_warehouse, bom_item.operation, bom_item.include_item_in_manufacturing,
|
||||
(Select idx from `tabBOM Item` where item_code = bom_item.item_code and parent = %(parent)s limit 1) as idx""")
|
||||
(Select idx from `tabBOM Item` where item_code = bom_item.item_code and parent = %(parent)s limit 1) as idx""",
|
||||
groupby_columns = """, bom_item.operation""")
|
||||
|
||||
items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom, "company": company }, as_dict=True)
|
||||
elif fetch_scrap_items:
|
||||
query = query.format(table="BOM Scrap Item", where_conditions="", select_columns=", bom_item.idx", is_stock_item=is_stock_item, qty_field="stock_qty")
|
||||
query = query.format(table="BOM Scrap Item", where_conditions="", select_columns=", bom_item.idx", is_stock_item=is_stock_item, qty_field="stock_qty", groupby_columns="")
|
||||
items = frappe.db.sql(query, { "qty": qty, "bom": bom, "company": company }, as_dict=True)
|
||||
else:
|
||||
query = query.format(table="BOM Item", where_conditions="", is_stock_item=is_stock_item,
|
||||
qty_field="stock_qty" if fetch_qty_in_stock_uom else "qty",
|
||||
select_columns = ", bom_item.uom, bom_item.conversion_factor, bom_item.source_warehouse, bom_item.idx, bom_item.operation, bom_item.include_item_in_manufacturing")
|
||||
select_columns = ", bom_item.uom, bom_item.conversion_factor, bom_item.source_warehouse, bom_item.idx, bom_item.operation, bom_item.include_item_in_manufacturing",
|
||||
groupby_columns = """, bom_item.operation""")
|
||||
items = frappe.db.sql(query, { "qty": qty, "bom": bom, "company": company }, as_dict=True)
|
||||
|
||||
for item in items:
|
||||
if item.item_code in item_dict:
|
||||
item_dict[item.item_code]["qty"] += flt(item.qty)
|
||||
key = (item.item_code)
|
||||
if item.operation:
|
||||
key = (item.item_code, item.operation)
|
||||
|
||||
if key in item_dict:
|
||||
item_dict[key]["qty"] += flt(item.qty)
|
||||
else:
|
||||
item_dict[item.item_code] = item
|
||||
item_dict[key] = item
|
||||
|
||||
for item, item_details in item_dict.items():
|
||||
for d in [["Account", "expense_account", "default_expense_account"],
|
||||
|
||||
Reference in New Issue
Block a user