From d87b9825b5abb0ecbfa53c1b7651618007054d76 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 12 Nov 2025 12:19:49 +0530 Subject: [PATCH] fix: current qty in stock reco --- .../stock_reconciliation/stock_reconciliation.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index a645997002..5a229f5308 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -18,7 +18,7 @@ from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle impor get_available_serial_nos, ) from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos -from erpnext.stock.utils import get_incoming_rate, get_stock_balance +from erpnext.stock.utils import get_combine_datetime, get_incoming_rate, get_stock_balance class OpeningEntryAccountError(frappe.ValidationError): @@ -1060,6 +1060,7 @@ class StockReconciliation(StockController): self.posting_date, self.posting_time, self.name, + sle_creation, ) precesion = row.precision("current_qty") @@ -1219,8 +1220,11 @@ class StockReconciliation(StockController): return current_qty -def get_batch_qty_for_stock_reco(item_code, warehouse, batch_no, posting_date, posting_time, voucher_no): +def get_batch_qty_for_stock_reco( + item_code, warehouse, batch_no, posting_date, posting_time, voucher_no, sle_creation +): ledger = frappe.qb.DocType("Stock Ledger Entry") + posting_datetime = get_combine_datetime(posting_date, posting_time) query = ( frappe.qb.from_(ledger) @@ -1233,12 +1237,11 @@ def get_batch_qty_for_stock_reco(item_code, warehouse, batch_no, posting_date, p & (ledger.docstatus == 1) & (ledger.is_cancelled == 0) & (ledger.batch_no == batch_no) - & (ledger.posting_date <= posting_date) + & (ledger.voucher_no != voucher_no) & ( - CombineDatetime(ledger.posting_date, ledger.posting_time) - <= CombineDatetime(posting_date, posting_time) + (ledger.posting_datetime < posting_datetime) + | ((ledger.posting_datetime == posting_datetime) & (ledger.creation < sle_creation)) ) - & (ledger.voucher_no != voucher_no) ) .groupby(ledger.batch_no) ) -- GitLab