Merge pull request #33248 from QwQuan/develop

fix: bugs in zh.csv
diff --git a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py
index 16c25ce..109d9ab 100644
--- a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py
+++ b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py
@@ -49,7 +49,7 @@
 					parent.bom_no,
 					parent.fg_warehouse.as_("warehouse"),
 				)
-				.where(parent.status.notin(["Completed", "Stopped"]))
+				.where(parent.status.notin(["Completed", "Stopped", "Closed"]))
 			)
 
 			if order_by == "Planned Start Date":
@@ -79,10 +79,11 @@
 				query = query.where(child.parent.isin(self.filters.docnames))
 
 			if doctype == "Sales Order":
-				query = query.select(
-					child.delivery_date,
-					parent.base_grand_total,
-				).where((child.stock_qty > child.produced_qty) & (parent.per_delivered < 100.0))
+				query = query.select(child.delivery_date, parent.base_grand_total,).where(
+					(child.stock_qty > child.produced_qty)
+					& (parent.per_delivered < 100.0)
+					& (parent.status.notin(["Completed", "Closed"]))
+				)
 
 				if order_by == "Delivery Date":
 					query = query.orderby(child.delivery_date, order=Order.asc)
@@ -91,7 +92,9 @@
 
 			elif doctype == "Material Request":
 				query = query.select(child.schedule_date,).where(
-					(parent.per_ordered < 100) & (parent.material_request_type == "Manufacture")
+					(parent.per_ordered < 100)
+					& (parent.material_request_type == "Manufacture")
+					& (parent.status != "Stopped")
 				)
 
 				if order_by == "Required Date":
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index d0eb377..60c3356 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -6,7 +6,7 @@
 
 import frappe
 import frappe.defaults
-from frappe import _, msgprint
+from frappe import _, msgprint, qb
 from frappe.contacts.address_and_contact import (
 	delete_contact_and_address,
 	load_address_and_contact,
@@ -732,12 +732,15 @@
 @frappe.validate_and_sanitize_search_inputs
 def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, filters):
 	customer = filters.get("customer")
-	return frappe.db.sql(
-		"""
-		select `tabContact`.name from `tabContact`, `tabDynamic Link`
-			where `tabContact`.name = `tabDynamic Link`.parent and `tabDynamic Link`.link_name = %(customer)s
-			and `tabDynamic Link`.link_doctype = 'Customer'
-			and `tabContact`.name like %(txt)s
-		""",
-		{"customer": customer, "txt": "%%%s%%" % txt},
+
+	con = qb.DocType("Contact")
+	dlink = qb.DocType("Dynamic Link")
+
+	return (
+		qb.from_(con)
+		.join(dlink)
+		.on(con.name == dlink.parent)
+		.select(con.name, con.full_name, con.email_id)
+		.where((dlink.link_name == customer) & (con.name.like(f"%{txt}%")))
+		.run()
 	)
diff --git a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py
index 8170009..d364b57 100644
--- a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py
+++ b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py
@@ -45,7 +45,7 @@
 	return frappe.get_all(
 		"Warehouse",
 		fields=["name", "parent_warehouse", "is_group"],
-		filters={"company": report_filters.company, "disabled": 0},
+		filters={"company": report_filters.company},
 		order_by="lft",
 	)
 
@@ -55,9 +55,10 @@
 	warehouses = get_warehouses(filters)
 
 	for warehouse in warehouses:
-		warehouse["stock_balance"] = warehouse_balance.get(warehouse.name, 0)
+		warehouse.stock_balance = warehouse_balance.get(warehouse.name, 0) or 0.0
 
 	update_indent(warehouses)
+	set_balance_in_parent(warehouses)
 
 	return warehouses
 
@@ -69,13 +70,26 @@
 			warehouse.indent = indent
 			for child in warehouses:
 				if child.parent_warehouse == warehouse.name:
-					warehouse.stock_balance += child.stock_balance
 					add_indent(child, indent + 1)
 
 		if warehouse.is_group:
 			add_indent(warehouse, warehouse.indent or 0)
 
 
+def set_balance_in_parent(warehouses):
+	# sort warehouses by indent in descending order
+	warehouses = sorted(warehouses, key=lambda x: x.get("indent", 0), reverse=1)
+
+	for warehouse in warehouses:
+
+		def update_balance(warehouse, balance):
+			for parent in warehouses:
+				if warehouse.parent_warehouse == parent.name:
+					parent.stock_balance += balance
+
+		update_balance(warehouse, warehouse.stock_balance)
+
+
 def get_columns():
 	return [
 		{