From 432b03572adf1772e657c61901c75028f276264d Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 20 Oct 2019 19:47:52 +0530 Subject: [PATCH] fix: stock balance report not working if actual qty is zero --- erpnext/stock/report/stock_balance/stock_balance.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py index e5ae70c8d4..68b8b502e5 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.py +++ b/erpnext/stock/report/stock_balance/stock_balance.py @@ -39,6 +39,9 @@ def execute(filters=None): data = [] conversion_factors = {} + + _func = lambda x: x[1] + for (company, item, warehouse) in sorted(iwb_map): if item_map.get(item): qty_dict = iwb_map[(company, item, warehouse)] @@ -70,7 +73,9 @@ def execute(filters=None): 'latest_age': 0 } if fifo_queue: - fifo_queue = sorted(fifo_queue, key=lambda fifo_data: fifo_data[1]) + fifo_queue = sorted(filter(_func, fifo_queue), key=_func) + if not fifo_queue: continue + stock_ageing_data['average_age'] = get_average_age(fifo_queue, to_date) stock_ageing_data['earliest_age'] = date_diff(to_date, fifo_queue[0][1]) stock_ageing_data['latest_age'] = date_diff(to_date, fifo_queue[-1][1])