Merge pull request #4866 from neilLasrado/develop

Fixes in Setup Wizard
diff --git a/erpnext/public/js/setup_wizard.js b/erpnext/public/js/setup_wizard.js
index 9c6cd03..b2693b9 100644
--- a/erpnext/public/js/setup_wizard.js
+++ b/erpnext/public/js/setup_wizard.js
@@ -9,43 +9,8 @@
 
 function load_erpnext_slides() {
 	$.extend(erpnext.wiz, {
-		user: {
-			title: __("The First User: You"),
-			icon: "icon-user",
-			fields: [
-				{"fieldname": "first_name", "label": __("First Name"), "fieldtype": "Data",
-					reqd:1},
-				{"fieldname": "last_name", "label": __("Last Name"), "fieldtype": "Data"},
-				{"fieldname": "email", "label": __("Email Address"), "fieldtype": "Data",
-					reqd:1, "description": __("You will use it to Login"), "options":"Email"},
-				{"fieldname": "password", "label": __("Password"), "fieldtype": "Password",
-					reqd:1},
-				{fieldtype:"Attach Image", fieldname:"attach_user",
-					label: __("Attach Your Picture"), is_private: 0},
-			],
-			help: __('The first user will become the System Manager (you can change this later).'),
-			onload: function(slide) {
-				if(user!=="Administrator") {
-					slide.form.fields_dict.password.$wrapper.toggle(false);
-					slide.form.fields_dict.email.$wrapper.toggle(false);
-					slide.form.fields_dict.first_name.set_input(frappe.boot.user.first_name);
-					slide.form.fields_dict.last_name.set_input(frappe.boot.user.last_name);
-
-					var user_image = frappe.get_cookie("user_image");
-					if(user_image) {
-						var $attach_user = slide.form.fields_dict.attach_user.$wrapper;
-						$attach_user.find(".missing-image").toggle(false);
-						$attach_user.find("img").attr("src", decodeURIComponent(user_image)).toggle(true);
-					}
-
-					delete slide.form.fields_dict.email;
-					delete slide.form.fields_dict.password;
-				}
-			},
-			css_class: "single-column"
-		},
-
 		org: {
+			app_name: "erpnext",
 			title: __("The Organization"),
 			icon: "icon-building",
 			fields: [
@@ -160,6 +125,7 @@
 		},
 
 		branding: {
+			app_name: "erpnext",
 			icon: "icon-bookmark",
 			title: __("The Brand"),
 			help: __('Upload your letter head and logo. (you can edit them later).'),
@@ -181,10 +147,11 @@
 		},
 
 		users: {
+			app_name: "erpnext",
 			icon: "icon-money",
-			"title": __("Add Users"),
-			"help": __("Add users to your organization, other than yourself"),
-			"fields": [],
+			title: __("Add Users"),
+			help: __("Add users to your organization, other than yourself"),
+			fields: [],
 			before_load: function(slide) {
 				slide.fields = [];
 				for(var i=1; i<5; i++) {
@@ -209,9 +176,10 @@
 		},
 
 		taxes: {
+			app_name: "erpnext",
 			icon: "icon-money",
-			"title": __("Add Taxes"),
-			"help": __("List your tax heads (e.g. VAT, Customs etc; they should have unique names) and their standard rates. This will create a standard template, which you can edit and add more later."),
+			title: __("Add Taxes"),
+			help: __("List your tax heads (e.g. VAT, Customs etc; they should have unique names) and their standard rates. This will create a standard template, which you can edit and add more later."),
 			"fields": [],
 			before_load: function(slide) {
 				slide.fields = [];
@@ -229,10 +197,11 @@
 		},
 
 		customers: {
+			app_name: "erpnext",
 			icon: "icon-group",
-			"title": __("Your Customers"),
-			"help": __("List a few of your customers. They could be organizations or individuals."),
-			"fields": [],
+			title: __("Your Customers"),
+			help: __("List a few of your customers. They could be organizations or individuals."),
+			fields: [],
 			before_load: function(slide) {
 				slide.fields = [];
 				for(var i=1; i<6; i++) {
@@ -251,10 +220,11 @@
 		},
 
 		suppliers: {
+			app_name: "erpnext",
 			icon: "icon-group",
-			"title": __("Your Suppliers"),
-			"help": __("List a few of your suppliers. They could be organizations or individuals."),
-			"fields": [],
+			title: __("Your Suppliers"),
+			help: __("List a few of your suppliers. They could be organizations or individuals."),
+			fields: [],
 			before_load: function(slide) {
 				slide.fields = [];
 				for(var i=1; i<6; i++) {
@@ -273,10 +243,11 @@
 		},
 
 		items: {
+			app_name: "erpnext",
 			icon: "icon-barcode",
-			"title": __("Your Products or Services"),
-			"help": __("List your products or services that you buy or sell. Make sure to check the Item Group, Unit of Measure and other properties when you start."),
-			"fields": [],
+			title: __("Your Products or Services"),
+			help: __("List your products or services that you buy or sell. Make sure to check the Item Group, Unit of Measure and other properties when you start."),
+			fields: [],
 			before_load: function(slide) {
 				slide.fields = [];
 				for(var i=1; i<6; i++) {
@@ -336,7 +307,6 @@
 
 frappe.wiz.on("before_load", function() {
 	load_erpnext_slides();
-	frappe.wiz.add_slide(erpnext.wiz.user);
 	frappe.wiz.add_slide(erpnext.wiz.org);
 	frappe.wiz.add_slide(erpnext.wiz.branding);
 	frappe.wiz.add_slide(erpnext.wiz.users);
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index b4e19da..d218793 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -12,7 +12,7 @@
 	frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
 	set_single_defaults()
 	feature_setup()
-	from erpnext.setup.setup_wizard.setup_wizard import add_all_roles_to
+	from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
 	add_all_roles_to("Administrator")
 	add_web_forms()
 	frappe.db.commit()
diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py
index 890f317..5a04682 100644
--- a/erpnext/setup/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/setup_wizard/setup_wizard.py
@@ -19,8 +19,7 @@
 		frappe.throw(_("Setup Already Complete!!"))
 
 	install_fixtures.install(args.get("country"))
-
-	update_user_name(args)
+	
 	create_fiscal_year_and_company(args)
 	create_users(args)
 	set_defaults(args)
@@ -54,67 +53,32 @@
 
 			pass
 
-
-def update_user_name(args):
-	if args.get("email"):
-		args['name'] = args.get("email")
-
-		_mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True
-		doc = frappe.get_doc({
-			"doctype":"User",
-			"email": args.get("email"),
-			"first_name": args.get("first_name"),
-			"last_name": args.get("last_name")
-		})
-		doc.flags.no_welcome_mail = True
-		doc.insert()
-		frappe.flags.mute_emails = _mute_emails
-		from frappe.auth import _update_password
-		_update_password(args.get("email"), args.get("password"))
-
-	else:
-		args['name'] = frappe.session.user
-
-		# Update User
-		if not args.get('last_name') or args.get('last_name')=='None':
-				args['last_name'] = None
-		frappe.db.sql("""update `tabUser` SET first_name=%(first_name)s,
-			last_name=%(last_name)s WHERE name=%(name)s""", args)
-
-	if args.get("attach_user"):
-		attach_user = args.get("attach_user").split(",")
-		if len(attach_user)==3:
-			filename, filetype, content = attach_user
-			fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
-			frappe.db.set_value("User", args.get("name"), "user_image", fileurl)
-
-	add_all_roles_to(args.get("name"))
-
 def create_fiscal_year_and_company(args):
-	curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
-	frappe.get_doc({
+	if (args.get('fy_start_date')):
+		curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
+		frappe.get_doc({
 		"doctype":"Fiscal Year",
 		'year': curr_fiscal_year,
 		'year_start_date': args.get('fy_start_date'),
 		'year_end_date': args.get('fy_end_date'),
-	}).insert()
-
+		}).insert()
+		args["curr_fiscal_year"] = curr_fiscal_year
+		
 	# Company
-	frappe.get_doc({
-		"doctype":"Company",
-		'domain': args.get("industry"),
-		'company_name':args.get('company_name').strip(),
-		'abbr':args.get('company_abbr'),
-		'default_currency':args.get('currency'),
-		'country': args.get('country'),
-		'chart_of_accounts': args.get(('chart_of_accounts')),
-	}).insert()
+	if (args.get('company_name')):	
+		frappe.get_doc({
+			"doctype":"Company",
+			'domain': args.get("industry"),
+			'company_name':args.get('company_name').strip(),
+			'abbr':args.get('company_abbr'),
+			'default_currency':args.get('currency'),
+			'country': args.get('country'),
+			'chart_of_accounts': args.get(('chart_of_accounts')),
+		}).insert()
 
-	# Bank Account
-	create_bank_account(args)
-
-	args["curr_fiscal_year"] = curr_fiscal_year
-
+		# Bank Account
+		create_bank_account(args)
+	
 def create_bank_account(args):
 	if args.get("bank_account"):
 		company_name = args.get('company_name').strip()
@@ -440,14 +404,6 @@
 			frappe.db.set_value("Website Settings", "Website Settings", "brand_html",
 				"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(fileurl, args.get("company_name").strip()))
 
-def add_all_roles_to(name):
-	user = frappe.get_doc("User", name)
-	for role in frappe.db.sql("""select name from tabRole"""):
-		if role[0] not in ["Administrator", "Guest", "All", "Customer", "Supplier", "Partner", "Employee"]:
-			d = user.append("user_roles")
-			d.role = role[0]
-	user.save()
-
 def create_territories():
 	"""create two default territories, one for home country and one named Rest of the World"""
 	from frappe.utils.nestedset import get_root_of