mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 09:43:49 +00:00
fix: incorrect current qty in stock reco (#51152)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user