diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index e314dd46e47..a76f40d713b 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -72,6 +72,7 @@ def execute(filters=None): inv_dimension_wise_dict, filters, inv_dimension_key=inv_dimension_key, opening_row=opening_row ) + item_wh_wise_prev_sle = {} for sle in sl_entries: item_detail = item_details[sle.item_code] @@ -113,6 +114,21 @@ def execute(filters=None): elif sle.voucher_type == "Stock Reconciliation": sle["in_out_rate"] = sle.valuation_rate + if ( + sle.voucher_type == "Stock Reconciliation" + and not sle.in_qty + and not sle.out_qty + and not sle.actual_qty + ): + if prev_sle := item_wh_wise_prev_sle.get((sle.item_code, sle.warehouse)): + bal_qty = prev_sle.get("qty_after_transaction", 0) + qty = sle.qty_after_transaction - bal_qty + if qty > 0: + sle.in_qty = qty + elif qty < 0: + sle.out_qty = qty + + item_wh_wise_prev_sle[(sle.item_code, sle.warehouse)] = sle data.append(sle) if include_uom: