From 5979683e8e45a9ae4b2b58db854707e40a9a6338 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 (cherry picked from commit 58315bc963d7fea5ac0a2aba417cef5696472a92) # Conflicts: # erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py --- .../stock_reconciliation.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 59208725e7d..18f9708349c 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -13,7 +13,11 @@ from erpnext.controllers.stock_controller import StockController from erpnext.stock.doctype.batch.batch import get_batch_qty from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos +<<<<<<< HEAD from erpnext.stock.utils import get_stock_balance +======= +from erpnext.stock.utils import get_combine_datetime, get_incoming_rate, get_stock_balance +>>>>>>> 58315bc963 (fix: current qty in stock reco) class OpeningEntryAccountError(frappe.ValidationError): @@ -646,6 +650,7 @@ class StockReconciliation(StockController): self.posting_date, self.posting_time, self.name, + sle_creation, ) precesion = row.precision("current_qty") @@ -705,8 +710,11 @@ class StockReconciliation(StockController): return allow_negative_stock -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) @@ -719,12 +727,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) - & ( - CombineDatetime(ledger.posting_date, ledger.posting_time) - <= CombineDatetime(posting_date, posting_time) - ) & (ledger.voucher_no != voucher_no) + & ( + (ledger.posting_datetime < posting_datetime) + | ((ledger.posting_datetime == posting_datetime) & (ledger.creation < sle_creation)) + ) ) .groupby(ledger.batch_no) )