feat: validate negative stock for inventory dimension (backport #37373) (#37383)

* feat: validate negative stock for inventory dimension (#37373)

* feat: validate negative stock for inventory dimension

* test: test case for validate negative stock for inv dimension

(cherry picked from commit 1480acabb0faeae61c7c055bb7d1e81877b87cfb)

# Conflicts:
#	erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
#	erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
#	erpnext/stock/stock_ledger.py

* chore: fix conflicts

* chore: fix conflicts

* chore: fix conflicts

* chore: fix linter issue

* chore: fix linter issue

* chore: fix linter issue

* chore: fix linter issue

* chore: fix linter issue

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index 0244406..bd0d469 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -95,6 +95,7 @@
 	posting_time=None,
 	with_valuation_rate=False,
 	with_serial_no=False,
+	inventory_dimensions_dict=None,
 ):
 	"""Returns stock balance quantity at given warehouse on given posting date or current date.
 
@@ -114,7 +115,13 @@
 		"posting_time": posting_time,
 	}
 
-	last_entry = get_previous_sle(args)
+	extra_cond = ""
+	if inventory_dimensions_dict:
+		for field, value in inventory_dimensions_dict.items():
+			args[field] = value
+			extra_cond += f" and {field} = %({field})s"
+
+	last_entry = get_previous_sle(args, extra_cond=extra_cond)
 
 	if with_valuation_rate:
 		if with_serial_no: