From c173643fe8a7da0af594cb8c137d4c9d5e766cf4 Mon Sep 17 00:00:00 2001 From: R-Jayaraman Date: Tue, 28 Jul 2026 18:57:06 +0530 Subject: [PATCH] fix: guard against None row in get_stock_balance_for row defaults to None but was dereferenced unconditionally when computing the incoming rate for batch-tracked items, causing an AttributeError for any caller (e.g. direct API calls) that omits row while still passing batch_no. The other two row accesses in this function already guard against None; this brings the incoming-rate check in line with them. (cherry picked from commit f9d25bc3d334ca0dbffee9b0be174eb8ba897e0b) # Conflicts: # erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py --- .../stock_reconciliation.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index bd789e9785e..a0ed27efebf 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -1381,7 +1381,25 @@ def get_stock_balance_for( or 0 ) +<<<<<<< HEAD if row.use_serial_batch_fields and row.batch_no and (qty or row.current_qty): +======= + if has_serial_no: + serial_no_details = get_available_serial_nos( + frappe._dict( + { + "item_code": item_code, + "warehouse": warehouse, + "posting_datetime": combine_datetime(posting_date, posting_time), + "ignore_warehouse": 1, + "has_batch_no": 1, + } + ) + ) + serial_nos = "\n".join(d.serial_no for d in serial_no_details if d.batch_no == batch_no) + + if row and row.use_serial_batch_fields and row.batch_no and (qty or row.current_qty): +>>>>>>> f9d25bc3d3 (fix: guard against None row in get_stock_balance_for) rate = get_incoming_rate( frappe._dict( {