From facd2027c3e26ecb6a17a5ca29ad417b604c2948 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 9 Jul 2025 16:05:26 +0530 Subject: [PATCH] feat: batch rate (valuation) in Batch-Wise Balance History report (cherry picked from commit 8a2a845a16a00fb2d48664ca0b107cc6eabd7f3f) --- .../batch_wise_balance_history.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py index 99e0676eca3..f895947f503 100644 --- a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py +++ b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py @@ -56,6 +56,11 @@ def execute(filters=None): flt(qty_dict.in_qty, float_precision), flt(qty_dict.out_qty, float_precision), flt(qty_dict.bal_qty, float_precision), + flt( + (qty_dict.bal_value / qty_dict.bal_qty) if qty_dict.bal_qty else 0, + float_precision, + ), + flt(qty_dict.bal_value, float_precision), item_map[item]["stock_uom"], ] ) @@ -68,14 +73,16 @@ def get_columns(filters): columns = [ _("Item") + ":Link/Item:100", - _("Item Name") + "::150", - _("Description") + "::150", + _("Item Name") + "::120", + _("Description") + "::90", _("Warehouse") + ":Link/Warehouse:100", _("Batch") + ":Link/Batch:100", _("Opening Qty") + ":Float:90", _("In Qty") + ":Float:80", _("Out Qty") + ":Float:80", - _("Balance Qty") + ":Float:90", + _("Balance Qty") + ":Float:120", + _("Valuation Rate") + ":Float:120", + _("Balance Value") + ":Currency:120", _("UOM") + "::90", ] @@ -107,6 +114,7 @@ def get_stock_ledger_entries_for_batch_no(filters): sle.batch_no, sle.posting_date, fn.Sum(sle.actual_qty).as_("actual_qty"), + fn.Sum(sle.stock_value_difference).as_("stock_value_difference"), ) .where( (sle.docstatus < 2) @@ -151,6 +159,7 @@ def get_stock_ledger_entries_for_batch_bundle(filters): batch_package.batch_no, sle.posting_date, fn.Sum(batch_package.qty).as_("actual_qty"), + fn.Sum(batch_package.stock_value_difference).as_("stock_value_difference"), ) .where( (sle.docstatus < 2) @@ -191,7 +200,10 @@ def get_item_warehouse_batch_map(filters, float_precision): for d in sle: iwb_map.setdefault(d.item_code, {}).setdefault(d.warehouse, {}).setdefault( - d.batch_no, frappe._dict({"opening_qty": 0.0, "in_qty": 0.0, "out_qty": 0.0, "bal_qty": 0.0}) + d.batch_no, + frappe._dict( + {"opening_qty": 0.0, "in_qty": 0.0, "out_qty": 0.0, "bal_qty": 0.0, "bal_value": 0.0} + ), ) qty_dict = iwb_map[d.item_code][d.warehouse][d.batch_no] if d.posting_date < from_date: @@ -207,6 +219,7 @@ def get_item_warehouse_batch_map(filters, float_precision): ) qty_dict.bal_qty = flt(qty_dict.bal_qty, float_precision) + flt(d.actual_qty, float_precision) + qty_dict.bal_value += flt(d.stock_value_difference, float_precision) return iwb_map