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

This commit is contained in:
Mihir Kandoi
2026-03-18 18:49:30 +05:30
committed by GitHub
parent 0d8f6b05e3
commit 6cb6a52ded
2 changed files with 5 additions and 3 deletions

View File

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

View File

@@ -1781,7 +1781,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
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,
to get actual qty before transaction, this function
@@ -1797,7 +1797,7 @@ def get_previous_sle(args, for_update=False, extra_cond=None):
"""
args["name"] = args.get("sle", None) or ""
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 {}
@@ -1811,6 +1811,7 @@ def get_stock_ledger_entries(
debug=False,
check_serial_no=True,
extra_cond=None,
for_report=False,
):
"""get stock ledger entries filtered by specific posting datetime conditions"""
conditions = f" and posting_datetime {operator} %(posting_datetime)s"
@@ -1865,7 +1866,7 @@ def get_stock_ledger_entries(
if extra_cond:
conditions += f"{extra_cond}"
if previous_sle.get("project"):
if for_report and previous_sle.get("project"):
conditions += " and project = %(project)s"
# nosemgrep