Merge pull request #4207 from rmehta/rename-tool

[feature] rename via console merge with frappe/frappe#1349
diff --git a/erpnext/utilities/doctype/rename_tool/rename_tool.js b/erpnext/utilities/doctype/rename_tool/rename_tool.js
index 2632ddd..77d2ba3 100644
--- a/erpnext/utilities/doctype/rename_tool/rename_tool.js
+++ b/erpnext/utilities/doctype/rename_tool/rename_tool.js
@@ -21,7 +21,7 @@
 					select_doctype: frm.doc.select_doctype
 				},
 				callback: function(r) {
-					frm.get_field("rename_log").$wrapper.html(r.message);
+					frm.get_field("rename_log").$wrapper.html(r.message.join("<br>"));
 				}
 			});
 		});
diff --git a/erpnext/utilities/doctype/rename_tool/rename_tool.py b/erpnext/utilities/doctype/rename_tool/rename_tool.py
index 18cfebe..5e33f5f 100644
--- a/erpnext/utilities/doctype/rename_tool/rename_tool.py
+++ b/erpnext/utilities/doctype/rename_tool/rename_tool.py
@@ -5,9 +5,9 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe import _
 
 from frappe.model.document import Document
+from frappe.model.rename_doc import bulk_rename
 
 class RenameTool(Document):
 	pass
@@ -20,37 +20,13 @@
 @frappe.whitelist()
 def upload(select_doctype=None, rows=None):
 	from frappe.utils.csvutils import read_csv_content_from_attached_file
-	from frappe.model.rename_doc import rename_doc
-
 	if not select_doctype:
 		select_doctype = frappe.form_dict.select_doctype
 
 	if not frappe.has_permission(select_doctype, "write"):
 		raise frappe.PermissionError
 
-	if not rows:
-		rows = read_csv_content_from_attached_file(frappe.get_doc("Rename Tool", "Rename Tool"))
-	if not rows:
-		frappe.throw(_("Please select a valid csv file with data"))
+	rows = read_csv_content_from_attached_file(frappe.get_doc("Rename Tool", "Rename Tool"))
 
-	max_rows = 500
-	if len(rows) > max_rows:
-		frappe.throw(_("Maximum {0} rows allowed").format(max_rows))
+	return bulk_rename(select_doctype, rows=rows)
 
-	rename_log = []
-	for row in rows:
-		# if row has some content
-		if len(row) > 1 and row[0] and row[1]:
-			try:
-				if rename_doc(select_doctype, row[0], row[1]):
-					rename_log.append(_("Successful: ") + row[0] + " -> " + row[1])
-					frappe.db.commit()
-				else:
-					rename_log.append(_("Ignored: ") + row[0] + " -> " + row[1])
-			except Exception, e:
-				rename_log.append("<span style='color: RED'>" + \
-					_("Failed: ") + row[0] + " -> " + row[1] + "</span>")
-				rename_log.append("<span style='margin-left: 20px;'>" + repr(e) + "</span>")
-				frappe.db.rollback()
-
-	return rename_log