Merge branch 'sort_bom_items' of https://github.com/creamdory/erpnext into creamdory-sort_bom_items
This commit is contained in:
commit
3f583b6dd2
@ -512,6 +512,7 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite
|
|||||||
|
|
||||||
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
|
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
|
||||||
query = """select
|
query = """select
|
||||||
|
(Select idx from `tabBOM Item` where item_code = bom_item.item_code and parent = %(parent)s ) as idx,
|
||||||
bom_item.item_code,
|
bom_item.item_code,
|
||||||
item.item_name,
|
item.item_name,
|
||||||
sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(qty)s as qty,
|
sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(qty)s as qty,
|
||||||
@ -531,20 +532,21 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite
|
|||||||
and item.name = bom_item.item_code
|
and item.name = bom_item.item_code
|
||||||
and is_stock_item = 1
|
and is_stock_item = 1
|
||||||
{where_conditions}
|
{where_conditions}
|
||||||
group by item_code, stock_uom"""
|
group by item_code, stock_uom
|
||||||
|
order by idx"""
|
||||||
|
|
||||||
if fetch_exploded:
|
if fetch_exploded:
|
||||||
query = query.format(table="BOM Explosion Item",
|
query = query.format(table="BOM Explosion Item",
|
||||||
where_conditions="""and item.is_sub_contracted_item = 0""",
|
where_conditions="""and item.is_sub_contracted_item = 0""",
|
||||||
select_columns = ", bom_item.source_warehouse")
|
select_columns = ", bom_item.source_warehouse")
|
||||||
items = frappe.db.sql(query, { "qty": qty, "bom": bom }, as_dict=True)
|
items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom }, as_dict=True)
|
||||||
elif fetch_scrap_items:
|
elif fetch_scrap_items:
|
||||||
query = query.format(table="BOM Scrap Item", where_conditions="", select_columns="")
|
query = query.format(table="BOM Scrap Item", where_conditions="", select_columns="")
|
||||||
items = frappe.db.sql(query, { "qty": qty, "bom": bom }, as_dict=True)
|
items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom }, as_dict=True)
|
||||||
else:
|
else:
|
||||||
query = query.format(table="BOM Item", where_conditions="",
|
query = query.format(table="BOM Item", where_conditions="",
|
||||||
select_columns = ", bom_item.source_warehouse")
|
select_columns = ", bom_item.source_warehouse")
|
||||||
items = frappe.db.sql(query, { "qty": qty, "bom": bom }, as_dict=True)
|
items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom }, as_dict=True)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
if item_dict.has_key(item.item_code):
|
if item_dict.has_key(item.item_code):
|
||||||
|
@ -437,7 +437,7 @@ class ProductionOrder(Document):
|
|||||||
item_dict = get_bom_items_as_dict(self.bom_no, self.company, qty=self.qty,
|
item_dict = get_bom_items_as_dict(self.bom_no, self.company, qty=self.qty,
|
||||||
fetch_exploded = self.use_multi_level_bom)
|
fetch_exploded = self.use_multi_level_bom)
|
||||||
|
|
||||||
for item in item_dict.values():
|
for item in sorted(item_dict.values(), key=lambda d: d['idx']):
|
||||||
self.append('required_items', {
|
self.append('required_items', {
|
||||||
'item_code': item.item_code,
|
'item_code': item.item_code,
|
||||||
'required_qty': item.qty,
|
'required_qty': item.qty,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user