mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 07:02:54 +00:00
fix: incorrect available qty for backdated stock reco with batch (#36581)
This commit is contained in:
@@ -199,6 +199,11 @@ def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False):
|
||||
sle.allow_negative_stock = allow_negative_stock
|
||||
sle.via_landed_cost_voucher = via_landed_cost_voucher
|
||||
sle.submit()
|
||||
|
||||
# Added to handle the case when the stock ledger entry is created from the repostig
|
||||
if args.get("creation_time") and args.get("voucher_type") == "Stock Reconciliation":
|
||||
sle.db_set("creation", args.get("creation_time"))
|
||||
|
||||
return sle
|
||||
|
||||
|
||||
@@ -564,12 +569,7 @@ class update_entries_after(object):
|
||||
if not self.args.get("sle_id"):
|
||||
self.get_dynamic_incoming_outgoing_rate(sle)
|
||||
|
||||
if (
|
||||
sle.voucher_type == "Stock Reconciliation"
|
||||
and sle.batch_no
|
||||
and sle.voucher_detail_no
|
||||
and sle.actual_qty < 0
|
||||
):
|
||||
if sle.voucher_type == "Stock Reconciliation" and sle.batch_no and sle.voucher_detail_no:
|
||||
self.reset_actual_qty_for_stock_reco(sle)
|
||||
|
||||
if (
|
||||
@@ -634,14 +634,17 @@ class update_entries_after(object):
|
||||
self.update_outgoing_rate_on_transaction(sle)
|
||||
|
||||
def reset_actual_qty_for_stock_reco(self, sle):
|
||||
current_qty = frappe.get_cached_value(
|
||||
"Stock Reconciliation Item", sle.voucher_detail_no, "current_qty"
|
||||
)
|
||||
doc = frappe.get_cached_doc("Stock Reconciliation", sle.voucher_no)
|
||||
doc.recalculate_current_qty(sle.voucher_detail_no, sle.creation, sle.actual_qty > 0)
|
||||
|
||||
if current_qty:
|
||||
sle.actual_qty = current_qty * -1
|
||||
elif current_qty == 0:
|
||||
sle.is_cancelled = 1
|
||||
if sle.actual_qty < 0:
|
||||
sle.actual_qty = (
|
||||
flt(frappe.db.get_value("Stock Reconciliation Item", sle.voucher_detail_no, "current_qty"))
|
||||
* -1
|
||||
)
|
||||
|
||||
if abs(sle.actual_qty) == 0.0:
|
||||
sle.is_cancelled = 1
|
||||
|
||||
def validate_negative_stock(self, sle):
|
||||
"""
|
||||
@@ -1433,8 +1436,6 @@ def update_qty_in_future_sle(args, allow_negative_stock=False):
|
||||
next_stock_reco_detail = get_next_stock_reco(args)
|
||||
if next_stock_reco_detail:
|
||||
detail = next_stock_reco_detail[0]
|
||||
if detail.batch_no:
|
||||
regenerate_sle_for_batch_stock_reco(detail)
|
||||
|
||||
# add condition to update SLEs before this date & time
|
||||
datetime_limit_condition = get_datetime_limit_condition(detail)
|
||||
@@ -1463,16 +1464,6 @@ def update_qty_in_future_sle(args, allow_negative_stock=False):
|
||||
validate_negative_qty_in_future_sle(args, allow_negative_stock)
|
||||
|
||||
|
||||
def regenerate_sle_for_batch_stock_reco(detail):
|
||||
doc = frappe.get_cached_doc("Stock Reconciliation", detail.voucher_no)
|
||||
doc.recalculate_current_qty(detail.item_code, detail.batch_no)
|
||||
|
||||
if not frappe.db.exists(
|
||||
"Repost Item Valuation", {"voucher_no": doc.name, "status": "Queued", "docstatus": "1"}
|
||||
):
|
||||
doc.repost_future_sle_and_gle(force=True)
|
||||
|
||||
|
||||
def get_stock_reco_qty_shift(args):
|
||||
stock_reco_qty_shift = 0
|
||||
if args.get("is_cancelled"):
|
||||
|
||||
Reference in New Issue
Block a user