[Fix] Alternative item, transferred qty issue for backflush method
diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py
index d10fd21..1624bb9 100644
--- a/erpnext/manufacturing/doctype/work_order/work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/work_order.py
@@ -554,12 +554,15 @@
consumed_qty = frappe.db.sql('''select sum(qty)
from `tabStock Entry` entry, `tabStock Entry Detail` detail
where
- entry.work_order = %s
+ entry.work_order = %(name)s
and (entry.purpose = "Material Consumption for Manufacture"
or entry.purpose = "Manufacture")
and entry.docstatus = 1
and detail.parent = entry.name
- and detail.item_code = %s''', (self.name, d.item_code))[0][0]
+ and (detail.item_code = %(item)s or detail.original_item = %(item)s)''', {
+ 'name': self.name,
+ 'item': d.item_code
+ })[0][0]
d.db_set('consumed_qty', flt(consumed_qty), update_modified = False)
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 586e21d..eed4016 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -832,7 +832,7 @@
def get_transfered_raw_materials(self):
transferred_materials = frappe.db.sql("""
select
- item_name, item_code, sum(qty) as qty, sed.t_warehouse as warehouse,
+ item_name, original_item, item_code, sum(qty) as qty, sed.t_warehouse as warehouse,
description, stock_uom, expense_account, cost_center
from `tabStock Entry` se,`tabStock Entry Detail` sed
where
@@ -866,8 +866,9 @@
for item in transferred_materials:
qty= item.qty
+ item_code = item.original_item or item.item_code
req_items = frappe.get_all('Work Order Item',
- filters={'parent': self.work_order, 'item_code': item.item_code},
+ filters={'parent': self.work_order, 'item_code': item_code},
fields=["required_qty", "consumed_qty"]
)
req_qty = flt(req_items[0].required_qty)
@@ -912,6 +913,7 @@
"stock_uom": item.stock_uom,
"expense_account": item.expense_account,
"cost_center": item.buying_cost_center,
+ "original_item": item.original_item
}
})
@@ -986,6 +988,7 @@
se_child.cost_center = item_dict[d].get("cost_center") or cost_center
se_child.allow_alternative_item = item_dict[d].get("allow_alternative_item", 0)
se_child.subcontracted_item = item_dict[d].get("main_item_code")
+ se_child.original_item = item_dict[d].get("original_item")
if item_dict[d].get("idx"):
se_child.idx = item_dict[d].get("idx")