Patches fixes (#13163)

* [fix] if serialised items not found then return

* [fix] unicode encoding in patch
diff --git a/erpnext/patches/v10_0/set_auto_created_serial_no_in_stock_entry.py b/erpnext/patches/v10_0/set_auto_created_serial_no_in_stock_entry.py
index afc4952..c6470f2 100644
--- a/erpnext/patches/v10_0/set_auto_created_serial_no_in_stock_entry.py
+++ b/erpnext/patches/v10_0/set_auto_created_serial_no_in_stock_entry.py
@@ -7,6 +7,9 @@
 def execute():
 	serialised_items = [d.name for d in frappe.get_all("Item", filters={"has_serial_no": 1})]
 
+	if not serialised_items:
+		return
+
 	for dt in ["Stock Entry Detail", "Purchase Receipt Item", "Purchase Invoice Item"]:
 		cond = ""
 		if dt=="Purchase Invoice Item":
diff --git a/erpnext/patches/v10_0/update_territory_and_customer_group.py b/erpnext/patches/v10_0/update_territory_and_customer_group.py
index a4a562c..afbbccf 100644
--- a/erpnext/patches/v10_0/update_territory_and_customer_group.py
+++ b/erpnext/patches/v10_0/update_territory_and_customer_group.py
@@ -13,22 +13,17 @@
 		for d in customer_group_fetch:
 			when_then = []
 			for customer in batch_customers:
+				value = frappe.db.escape(frappe.as_unicode(customer.get("customer_group")))
+
 				when_then.append('''
-					WHEN `{master_fieldname}` = "{docname}" and {linked_to_fieldname} != "{value}"
-					THEN "{value}"
-				'''.format(
-					master_fieldname=d["master_fieldname"],
-					linked_to_fieldname=d["linked_to_fieldname"],
-					docname=frappe.db.escape(frappe.as_unicode(customer.name)),
-					value=frappe.db.escape(frappe.as_unicode(customer.get("customer_group")))))
+					WHEN `%s` = "%s" and %s != "%s"
+					THEN "%s"
+				'''%(d["master_fieldname"], frappe.db.escape(frappe.as_unicode(customer.name)),
+					d["linked_to_fieldname"], value, value))
 
 			frappe.db.sql("""
 				update
-					`tab{doctype}`
+					`tab%s`
 				set
-					{linked_to_fieldname} = CASE {when_then_cond}  ELSE `{linked_to_fieldname}` END
-			""".format(
-				doctype = d['doctype'],
-				when_then_cond=" ".join(when_then),
-				linked_to_fieldname=d.linked_to_fieldname
-			))
+					%s = CASE %s  ELSE `%s` END
+			"""%(d['doctype'], d.linked_to_fieldname, " ".join(when_then), d.linked_to_fieldname))