fix: incorrect current qty in stock reco (backport #51152) (#51158)

* fix: incorrect current qty in stock reco (#51152)

(cherry picked from commit dec474ef3a)

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2025-12-17 13:46:31 +05:30
committed by GitHub
parent 069262dd4d
commit 89d6a8f02e
2 changed files with 17 additions and 24 deletions

View File

@@ -166,7 +166,9 @@ class Batch(Document):
for row in batches:
batch_qty += row.get("qty")
self.db_set("batch_qty", batch_qty)
if self.batch_qty != batch_qty:
self.db_set("batch_qty", batch_qty)
frappe.msgprint(_("Batch Qty updated to {0}").format(batch_qty), alert=True)
def set_batchwise_valuation(self):

View File

@@ -1227,32 +1227,23 @@ class StockReconciliation(StockController):
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)
.select(
Sum(ledger.actual_qty).as_("batch_qty"),
qty = (
get_batch_qty(
batch_no,
warehouse,
item_code,
creation=sle_creation,
posting_date=posting_date,
posting_time=posting_time,
ignore_voucher_nos=[voucher_no],
for_stock_levels=True,
consider_negative_batches=True,
do_not_check_future_batches=True,
)
.where(
(ledger.item_code == item_code)
& (ledger.warehouse == warehouse)
& (ledger.docstatus == 1)
& (ledger.is_cancelled == 0)
& (ledger.batch_no == batch_no)
& (ledger.voucher_no != voucher_no)
& (
(ledger.posting_datetime < posting_datetime)
| ((ledger.posting_datetime == posting_datetime) & (ledger.creation < sle_creation))
)
)
.groupby(ledger.batch_no)
or 0
)
sle = query.run(as_dict=True)
return flt(sle[0].batch_qty) if sle else 0
return flt(qty)
@frappe.whitelist()