3to4 fixes
diff --git a/erpnext/patches/4_0/fields_to_be_renamed.py b/erpnext/patches/4_0/fields_to_be_renamed.py
index 0c0a235..2bbd430 100644
--- a/erpnext/patches/4_0/fields_to_be_renamed.py
+++ b/erpnext/patches/4_0/fields_to_be_renamed.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe.model import rename_field
-
+from frappe.modules import scrub, get_doctype_module
 
 def execute():
 	rename_map = {
@@ -109,7 +109,7 @@
 			
 def reload_docs(docs):
 	for dn in docs:
-		frappe.reload_doc(get_module(dn),	"doctype", dn.lower().replace(" ", "_"))
+		frappe.reload_doc(get_doctype_module(dn), "doctype", scrub(dn))
 	
 	# reload all standard print formats
 	for pf in frappe.db.sql("""select name, module from `tabPrint Format` 
@@ -124,7 +124,8 @@
 	for r in frappe.db.sql("""select name, ref_doctype from `tabReport` 
 		where ifnull(is_standard, 'No') = 'Yes'
 		and report_type in ('Report Builder', 'Query Report')""", as_dict=1):
-			frappe.reload_doc(get_module(r.ref_doctype), "Report", r.name)
-			
-def get_module(dn):
-	return frappe.db.get_value("DocType", dn, "module").lower().replace(" ", "_")
\ No newline at end of file
+			try:
+				frappe.reload_doc(get_doctype_module(r.ref_doctype), "Report", r.name)
+			except Exception, e:
+				print e
+				pass
diff --git a/erpnext/patches/4_0/rename_sitemap_to_route.py b/erpnext/patches/4_0/rename_sitemap_to_route.py
index 0485bf9..b933e36 100644
--- a/erpnext/patches/4_0/rename_sitemap_to_route.py
+++ b/erpnext/patches/4_0/rename_sitemap_to_route.py
@@ -5,7 +5,12 @@
 	frappe.reload_doc("setup", "doctype", "item_group")
 	frappe.reload_doc("stock", "doctype", "item")
 	frappe.reload_doc("setup", "doctype", "sales_partner")
-	frappe.model.rename_field("Item Group", "parent_website_sitemap", "parent_website_route")
-	frappe.model.rename_field("Item", "parent_website_sitemap", "parent_website_route")
-	frappe.model.rename_field("Sales Partner", "parent_website_sitemap",
-		 "parent_website_route")
+	
+	try:
+		frappe.model.rename_field("Item Group", "parent_website_sitemap", "parent_website_route")
+		frappe.model.rename_field("Item", "parent_website_sitemap", "parent_website_route")
+		frappe.model.rename_field("Sales Partner", "parent_website_sitemap",
+			 "parent_website_route")
+	except Exception, e:
+		if e.args[0]!=1054:
+			raise
\ No newline at end of file
diff --git a/erpnext/patches/4_0/update_user_properties.py b/erpnext/patches/4_0/update_user_properties.py
index c07713e..5070bfd 100644
--- a/erpnext/patches/4_0/update_user_properties.py
+++ b/erpnext/patches/4_0/update_user_properties.py
@@ -102,5 +102,5 @@
 		group by parent, defkey, defvalue""", as_dict=1):
 		if d.cnt > 1:
 			# order by parenttype so that restriction does not get removed!
-			frappe.db.sql("""delete from tabDefaultValue where parent=%s, defkey=%s,
-				defvalue=%s order by parenttype limit %s""", (d.parent, d.defkey, d.defvalue, d.cnt-1))
+			frappe.db.sql("""delete from tabDefaultValue where `parent`=%s and `defkey`=%s and
+				`defvalue`=%s order by parenttype limit %s""", (d.parent, d.defkey, d.defvalue, d.cnt-1))