From fb21ce389345d61ccdfb4b2c0706853e23e9dbac Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 27 Feb 2014 13:18:20 +0530 Subject: [PATCH] 3to4 fixes --- erpnext/patches/4_0/fields_to_be_renamed.py | 13 +++++++------ erpnext/patches/4_0/rename_sitemap_to_route.py | 13 +++++++++---- erpnext/patches/4_0/update_user_properties.py | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/erpnext/patches/4_0/fields_to_be_renamed.py b/erpnext/patches/4_0/fields_to_be_renamed.py index 0c0a235835f..2bbd4300c93 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 execute(): 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 @@ def reload_docs(docs): 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 0485bf9528c..b933e364b40 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 @@ def execute(): 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 c07713ee8d3..5070bfdf1a7 100644 --- a/erpnext/patches/4_0/update_user_properties.py +++ b/erpnext/patches/4_0/update_user_properties.py @@ -102,5 +102,5 @@ def remove_duplicate_restrictions(): 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))