fix(get_stock_balance): validate inventory dimension fieldnames (backport #54587) (#54588)

* fix(`get_stock_balance`): validate inventory dimension fieldnames (#54587)

(cherry picked from commit 084c7f72f0)

# Conflicts:
#	erpnext/stock/utils.py

* chore: resolved conflicts

---------

Co-authored-by: diptanilsaha <diptanil@frappe.io>
This commit is contained in:
mergify[bot]
2026-04-28 18:14:07 +05:30
committed by GitHub
parent cceedd669f
commit 03f3a28f54

View File

@@ -10,9 +10,8 @@ from frappe.query_builder.functions import CombineDatetime, IfNull, Sum
from frappe.utils import cstr, flt, get_link_to_form, get_time, getdate, nowdate, nowtime
import erpnext
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import (
get_available_serial_nos,
)
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import get_available_serial_nos
from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
from erpnext.stock.serial_batch_bundle import BatchNoValuation, SerialNoValuation
from erpnext.stock.valuation import FIFOValuation, LIFOValuation
@@ -124,11 +123,19 @@ def get_stock_balance(
}
extra_cond = ""
if inventory_dimensions_dict:
inventory_dimensions_fieldname = [d.get("fieldname") for d in get_inventory_dimensions()]
for field, value in inventory_dimensions_dict.items():
column = frappe.utils.sanitize_column(field)
if field not in inventory_dimensions_fieldname:
frappe.throw(
_("{0} is not a valid {1} fieldname.").format(
frappe.bold(field), frappe.bold("Inventory Dimension")
)
)
args[field] = value
extra_cond += f" and {column} = %({field})s"
extra_cond += f" and {field} = %({field})s"
last_entry = get_previous_sle(args, extra_cond=extra_cond)