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

This commit is contained in:
rohitwaghchaure
2025-12-17 13:15:00 +05:30
committed by GitHub
parent 0b3e40b155
commit dec474ef3a
2 changed files with 16 additions and 22 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

@@ -1221,32 +1221,24 @@ 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_datetime=posting_datetime,
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()