Merge pull request #48489 from frappe/mergify/bp/version-15-hotfix/pr-48487

feat: batch rate (valuation) in Batch-Wise Balance History report (backport #48487)
This commit is contained in:
rohitwaghchaure
2025-07-09 16:48:05 +05:30
committed by GitHub

View File

@@ -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