From 03f3a28f54d8172d1512d5c70ac3afc6f2c23823 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:14:07 +0530 Subject: [PATCH] fix(`get_stock_balance`): validate inventory dimension fieldnames (backport #54587) (#54588) * fix(`get_stock_balance`): validate inventory dimension fieldnames (#54587) (cherry picked from commit 084c7f72f051963c35daac3eeb7664c935c172d2) # Conflicts: # erpnext/stock/utils.py * chore: resolved conflicts --------- Co-authored-by: diptanilsaha --- erpnext/stock/utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 0c03e350d02..8dfcf5a833e 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -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)