diff --git a/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.py b/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.py index 64363e20e394..a5690c477e4c 100644 --- a/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.py +++ b/erpnext/manufacturing/report/work_order_consumed_materials/work_order_consumed_materials.py @@ -50,7 +50,11 @@ def get_returned_materials(work_orders): raw_materials = frappe.get_all( "Stock Entry", - fields=["`tabStock Entry Detail`.`item_code`", "`tabStock Entry Detail`.`qty`"], + fields=[ + "`tabStock Entry`.`work_order`", + "`tabStock Entry Detail`.`item_code`", + "`tabStock Entry Detail`.`qty`", + ], filters=[ ["Stock Entry", "is_return", "=", 1], ["Stock Entry Detail", "docstatus", "=", 1], @@ -59,12 +63,14 @@ def get_returned_materials(work_orders): ) for d in raw_materials: - raw_materials_qty[d.item_code] += d.qty + key = (d.work_order, d.item_code) + raw_materials_qty[key] += d.qty for row in work_orders: row.returned_qty = 0.0 - if raw_materials_qty.get(row.raw_material_item_code): - row.returned_qty = raw_materials_qty.get(row.raw_material_item_code) + key = (row.parent, row.raw_material_item_code) + if raw_materials_qty.get(key): + row.returned_qty = raw_materials_qty.get(key) def get_fields():