fix: incorrect consumed qty if raw material with batch
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index c3a2560..55b4319 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -298,7 +298,7 @@
title=_("Limit Crossed"))
transferred_batch_qty_map = get_transferred_batch_qty_map(item.purchase_order, item.item_code)
- backflushed_batch_qty_map = get_backflushed_batch_qty_map(item.purchase_order, item.item_code)
+ # backflushed_batch_qty_map = get_backflushed_batch_qty_map(item.purchase_order, item.item_code)
for raw_material in transferred_raw_materials + non_stock_items:
rm_item_key = (raw_material.rm_item_code, item.purchase_order)
@@ -330,6 +330,8 @@
set_serial_nos(raw_material, consumed_serial_nos, qty)
if raw_material.batch_nos:
+ backflushed_batch_qty_map = raw_material_data.get('consumed_batch', {})
+
batches_qty = get_batches_with_qty(raw_material.rm_item_code, raw_material.main_item_code,
qty, transferred_batch_qty_map, backflushed_batch_qty_map, item.purchase_order)
for batch_data in batches_qty:
@@ -913,7 +915,8 @@
backflushed_raw_materials_map.setdefault(pr_key, frappe._dict({
"qty": 0.0,
"serial_no": [],
- "batch_no": []
+ "batch_no": [],
+ "consumed_batch": {}
}))
row = backflushed_raw_materials_map.get(pr_key)
@@ -923,6 +926,12 @@
if data.get(field):
row[field].append(data.get(field))
+ if data.get("batch_no"):
+ if data.get("batch_no") in row.consumed_batch:
+ row.consumed_batch[data.get("batch_no")] += data.consumed_qty
+ else:
+ row.consumed_batch[data.get("batch_no")] = data.consumed_qty
+
return backflushed_raw_materials_map
def get_supplied_items(item_code, purchase_receipt, references):
@@ -1067,14 +1076,12 @@
return backflushed_batch_qty_map
-def get_batches_with_qty(item_code, fg_item, required_qty, transferred_batch_qty_map, backflushed_batch_qty_map, po):
+def get_batches_with_qty(item_code, fg_item, required_qty, transferred_batch_qty_map, backflushed_batches, po):
# Returns available batches to be backflushed based on requirements
transferred_batches = transferred_batch_qty_map.get((item_code, fg_item), {})
if not transferred_batches:
transferred_batches = transferred_batch_qty_map.get((item_code, po), {})
- backflushed_batches = backflushed_batch_qty_map.get((item_code, fg_item), {})
-
available_batches = []
for (batch, transferred_qty) in transferred_batches.items():