fix: incorrect sle calculation when doc has project (#53599)

(cherry picked from commit 6cb6a52ded)
This commit is contained in:
Mihir Kandoi
2026-03-18 18:49:30 +05:30
committed by Mergify
parent 16fe458b92
commit 7acd435835
2 changed files with 5 additions and 3 deletions

View File

@@ -686,6 +686,7 @@ def get_opening_balance(filters, columns, sl_entries, inv_dimension_wise_value=N
"posting_time": "00:00:00", "posting_time": "00:00:00",
"project": project, "project": project,
}, },
for_report=True,
) )
# check if any SLEs are actually Opening Stock Reconciliation # check if any SLEs are actually Opening Stock Reconciliation

View File

@@ -1766,7 +1766,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
return sle[0] if sle else frappe._dict() return sle[0] if sle else frappe._dict()
def get_previous_sle(args, for_update=False, extra_cond=None): def get_previous_sle(args, for_update=False, extra_cond=None, for_report=False):
""" """
get the last sle on or before the current time-bucket, get the last sle on or before the current time-bucket,
to get actual qty before transaction, this function to get actual qty before transaction, this function
@@ -1782,7 +1782,7 @@ def get_previous_sle(args, for_update=False, extra_cond=None):
""" """
args["name"] = args.get("sle", None) or "" args["name"] = args.get("sle", None) or ""
sle = get_stock_ledger_entries( sle = get_stock_ledger_entries(
args, "<=", "desc", "limit 1", for_update=for_update, extra_cond=extra_cond args, "<=", "desc", "limit 1", for_update=for_update, extra_cond=extra_cond, for_report=for_report
) )
return sle and sle[0] or {} return sle and sle[0] or {}
@@ -1796,6 +1796,7 @@ def get_stock_ledger_entries(
debug=False, debug=False,
check_serial_no=True, check_serial_no=True,
extra_cond=None, extra_cond=None,
for_report=False,
): ):
"""get stock ledger entries filtered by specific posting datetime conditions""" """get stock ledger entries filtered by specific posting datetime conditions"""
conditions = f" and posting_datetime {operator} %(posting_datetime)s" conditions = f" and posting_datetime {operator} %(posting_datetime)s"
@@ -1850,7 +1851,7 @@ def get_stock_ledger_entries(
if extra_cond: if extra_cond:
conditions += f"{extra_cond}" conditions += f"{extra_cond}"
if previous_sle.get("project"): if for_report and previous_sle.get("project"):
conditions += " and project = %(project)s" conditions += " and project = %(project)s"
# nosemgrep # nosemgrep