[enhance] Add Issue Type and Opportunity Type masters (#11598)

* [enhance] added & linked Issue Type & Opportunity Type with opportunity

* [patch] create issue and opportunity type from the custom field if available

* [minor] issue_type and opportunity type should be mandatory

* [patches] removed try catch from the patch

* [fix] patch

* [refactor] cleanup issue/opportunity type
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 3801141..c3d7a2c 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -254,7 +254,7 @@
 						}
 					})
 				}, __("Get items from"));
-			// Get items from Opportunity 
+			// Get items from Opportunity
             this.frm.add_custom_button(__('Opportunity'),
 				function() {
 					erpnext.utils.map_current_doc({
@@ -264,11 +264,8 @@
 						setters: {
 							company: me.frm.doc.company
 						},
-						get_query_filters: {
-							enquiry_type: "Sales"
-						}
 					})
-				}, __("Get items from"));  
+				}, __("Get items from"));
 			// Get items from open Material Requests based on supplier
 			this.frm.add_custom_button(__('Possible Supplier'), function() {
 				// Create a dialog window for the user to pick their supplier
diff --git a/erpnext/crm/doctype/opportunity/opportunity.json b/erpnext/crm/doctype/opportunity/opportunity.json
index 89eb191..ea07ce2 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.json
+++ b/erpnext/crm/doctype/opportunity/opportunity.json
@@ -270,8 +270,8 @@
    "collapsible": 0, 
    "columns": 0, 
    "default": "Sales", 
-   "fieldname": "enquiry_type", 
-   "fieldtype": "Select", 
+   "fieldname": "opportunity_type", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -284,14 +284,14 @@
    "no_copy": 0, 
    "oldfieldname": "enquiry_type", 
    "oldfieldtype": "Select", 
-   "options": "Sales\nMaintenance", 
+   "options": "Opportunity Type", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 1, 
+   "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -1189,7 +1189,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-08-21 02:07:46.486433", 
+ "modified": "2017-11-15 17:44:46.241548", 
  "modified_by": "Administrator", 
  "module": "CRM", 
  "name": "Opportunity", 
@@ -1239,7 +1239,7 @@
  "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
- "search_fields": "status,transaction_date,customer,lead,enquiry_type,territory,company", 
+ "search_fields": "status,transaction_date,customer,lead,opportunity_type,territory,company", 
  "show_name_in_global_search": 1, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index e9a7baa..b8077fe 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -246,7 +246,7 @@
 			"doctype": "Quotation",
 			"field_map": {
 				"enquiry_from": "quotation_to",
-				"enquiry_type": "order_type",
+				"opportunity_type": "order_type",
 				"name": "enq_no",
 			}
 		},
@@ -267,10 +267,7 @@
 def make_request_for_quotation(source_name, target_doc=None):
 	doclist = get_mapped_doc("Opportunity", source_name, {
 		"Opportunity": {
-			"doctype": "Request for Quotation",
-			"validation": {
-				"enquiry_type": ["=", "Sales"]
-			}
+			"doctype": "Request for Quotation"
 		},
 		"Opportunity Item": {
 			"doctype": "Request for Quotation Item",
diff --git a/erpnext/crm/doctype/opportunity/opportunity_list.js b/erpnext/crm/doctype/opportunity/opportunity_list.js
index 55a5463..0dbbf8a 100644
--- a/erpnext/crm/doctype/opportunity/opportunity_list.js
+++ b/erpnext/crm/doctype/opportunity/opportunity_list.js
@@ -1,5 +1,5 @@
 frappe.listview_settings['Opportunity'] = {
-	add_fields: ["customer_name", "enquiry_type", "enquiry_from", "status"],
+	add_fields: ["customer_name", "opportunity_type", "enquiry_from", "status"],
 	get_indicator: function(doc) {
 		var indicator = [__(doc.status), frappe.utils.guess_colour(doc.status), "status,=," + doc.status];
 		if(doc.status=="Quotation") {
diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py
index 61b583c..658e31f 100644
--- a/erpnext/crm/doctype/opportunity/test_opportunity.py
+++ b/erpnext/crm/doctype/opportunity/test_opportunity.py
@@ -30,7 +30,7 @@
 		args = {
 			"doctype": "Opportunity",
 			"contact_email":"new.opportunity@example.com",
-			"enquiry_type": "Sales",
+			"opportunity_type": "Sales",
 			"with_items": 0,
 			"transaction_date": today()
 		}
@@ -65,7 +65,7 @@
 	opp_doc = frappe.get_doc({
 		"doctype": "Opportunity",
 		"enquiry_from": args.enquiry_from or "Customer",
-		"enquiry_type": "Sales",
+		"opportunity_type": "Sales",
 		"with_items": args.with_items or 0,
 		"transaction_date": today()
 	})
diff --git a/erpnext/crm/doctype/opportunity_type/__init__.py b/erpnext/crm/doctype/opportunity_type/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/crm/doctype/opportunity_type/__init__.py
diff --git a/erpnext/crm/doctype/opportunity_type/opportunity_type.js b/erpnext/crm/doctype/opportunity_type/opportunity_type.js
new file mode 100644
index 0000000..174625e
--- /dev/null
+++ b/erpnext/crm/doctype/opportunity_type/opportunity_type.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Opportunity Type', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/crm/doctype/opportunity_type/opportunity_type.json b/erpnext/crm/doctype/opportunity_type/opportunity_type.json
new file mode 100644
index 0000000..3ada0f1
--- /dev/null
+++ b/erpnext/crm/doctype/opportunity_type/opportunity_type.json
@@ -0,0 +1,135 @@
+{
+ "allow_copy": 0, 
+ "allow_guest_to_view": 0, 
+ "allow_import": 1, 
+ "allow_rename": 0, 
+ "autoname": "Prompt", 
+ "beta": 0, 
+ "creation": "2017-10-06 12:55:43.318773", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Setup", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Description", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "has_web_view": 0, 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2017-11-15 17:27:12.271303", 
+ "modified_by": "Administrator", 
+ "module": "CRM", 
+ "name": "Opportunity Type", 
+ "name_case": "Title Case", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "System Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Sales Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 0, 
+   "delete": 0, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Sales User", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 0
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "search_fields": "", 
+ "show_name_in_global_search": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "title_field": "", 
+ "track_changes": 1, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/crm/doctype/opportunity_type/opportunity_type.py b/erpnext/crm/doctype/opportunity_type/opportunity_type.py
new file mode 100644
index 0000000..48abac3
--- /dev/null
+++ b/erpnext/crm/doctype/opportunity_type/opportunity_type.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class OpportunityType(Document):
+	pass
diff --git a/erpnext/crm/doctype/opportunity_type/test_opportunity_type.js b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.js
new file mode 100644
index 0000000..3a1ede9
--- /dev/null
+++ b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Opportunity Type", function (assert) {
+	let done = assert.async();
+
+	// number of asserts
+	assert.expect(1);
+
+	frappe.run_serially([
+		// insert a new Opportunity Type
+		() => frappe.tests.make('Opportunity Type', [
+			// values to be set
+			{key: 'value'}
+		]),
+		() => {
+			assert.equal(cur_frm.doc.key, 'value');
+		},
+		() => done()
+	]);
+
+});
diff --git a/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py
new file mode 100644
index 0000000..6410bbc
--- /dev/null
+++ b/erpnext/crm/doctype/opportunity_type/test_opportunity_type.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+
+class TestOpportunityType(unittest.TestCase):
+	pass
diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py
index ddd36ef..54ea173 100644
--- a/erpnext/demo/user/sales.py
+++ b/erpnext/demo/user/sales.py
@@ -54,7 +54,7 @@
 		"doctype": "Opportunity",
 		"enquiry_from": "Customer",
 		"customer": get_random("Customer"),
-		"enquiry_type": "Sales",
+		"opportunity_type": "Sales",
 		"with_items": 1,
 		"transaction_date": frappe.flags.current_date,
 	})
diff --git a/erpnext/hub_node/data_migration_mapping/hub_message_to_lead/__init__.py b/erpnext/hub_node/data_migration_mapping/hub_message_to_lead/__init__.py
index 79769ee..0ea1bc4 100644
--- a/erpnext/hub_node/data_migration_mapping/hub_message_to_lead/__init__.py
+++ b/erpnext/hub_node/data_migration_mapping/hub_message_to_lead/__init__.py
@@ -20,7 +20,7 @@
 	opportunity = frappe.get_doc({
 		'doctype': 'Opportunity',
 		'naming_series': 'OPTY-',
-		'enquiry_type': 'Sales',
+		'opportunity_type': 'Hub',
 		'enquiry_from': 'Lead',
 		'status': 'Open',
 		'lead': lead.name,
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 6cb87b6..5d522b2 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -462,3 +462,4 @@
 execute:frappe.delete_doc_if_exists("DocType", "Program Fee")
 erpnext.patches.v9_0.update_employee_loan_details
 erpnext.patches.v9_2.delete_healthcare_domain_default_items
+erpnext.patches.v9_1.create_issue_opportunity_type
diff --git a/erpnext/patches/v9_1/__init__.py b/erpnext/patches/v9_1/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v9_1/__init__.py
diff --git a/erpnext/patches/v9_1/create_issue_opportunity_type.py b/erpnext/patches/v9_1/create_issue_opportunity_type.py
new file mode 100644
index 0000000..b5070b0
--- /dev/null
+++ b/erpnext/patches/v9_1/create_issue_opportunity_type.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+
+def execute():
+	# delete custom field if exists
+	for fieldname in ('issue_type', 'opportunity_type'):
+		custom_field = frappe.db.get_value("Custom Field", {"fieldname": fieldname})
+		if custom_field:
+			frappe.delete_doc("Custom Field", custom_field, ignore_permissions=True)
+
+	frappe.reload_doc('support', 'doctype', 'issue_type')
+	frappe.reload_doc('support', 'doctype', 'issue')
+	frappe.reload_doc('crm', 'doctype', 'opportunity_type')
+	frappe.reload_doc('crm', 'doctype', 'opportunity')
+
+	# rename enquiry_type -> opportunity_type
+	from frappe.model.utils.rename_field import rename_field
+	rename_field('Opportunity', 'enquiry_type', 'opportunity_type')
+
+	# create values if already set
+	for opts in (('Issue', 'issue_type', 'Issue Type'),
+		('Opportunity', 'opportunity_type', 'Opportunity Type')):
+		for d in frappe.db.sql('select distinct {0} from `tab{1}`'.format(opts[1], opts[0])):
+			if not frappe.db.exists(opts[2], d[0]):
+				frappe.get_doc(dict(doctype = opts[2], name=d[0])).insert()
+
+	# fixtures
+	for name in ('Hub', _('Sales'), _('Support'), _('Maintenance')):
+		if not frappe.db.exists('Opportunity', name):
+			frappe.get_doc(dict(doctype = 'Opportunity Type', name=name)).insert()
diff --git a/erpnext/setup/setup_wizard/install_fixtures.py b/erpnext/setup/setup_wizard/install_fixtures.py
index e6a4a81..bc0d2a3 100644
--- a/erpnext/setup/setup_wizard/install_fixtures.py
+++ b/erpnext/setup/setup_wizard/install_fixtures.py
@@ -212,6 +212,11 @@
 		{'doctype': "Party Type", "party_type": "Supplier"},
 		{'doctype': "Party Type", "party_type": "Employee"},
 
+		{'doctype': "Opportunity Type", "name": "Hub"},
+		{'doctype': "Opportunity Type", "name": _("Sales")},
+		{'doctype': "Opportunity Type", "name": _("Support")},
+		{'doctype': "Opportunity Type", "name": _("Maintenance")},
+
 		{'doctype': "Project Type", "project_type": "Internal"},
 		{'doctype': "Project Type", "project_type": "External"},
 		{'doctype': "Project Type", "project_type": "Other"},
diff --git a/erpnext/setup/setup_wizard/sample_data.py b/erpnext/setup/setup_wizard/sample_data.py
index 43911f0..e58b5f2 100644
--- a/erpnext/setup/setup_wizard/sample_data.py
+++ b/erpnext/setup/setup_wizard/sample_data.py
@@ -38,7 +38,7 @@
 		"doctype": "Opportunity",
 		"enquiry_from": "Customer",
 		"customer": customer,
-		"enquiry_type": "Sales",
+		"opportunity_type": _("Sales"),
 		"with_items": 1
 	})
 
diff --git a/erpnext/support/doctype/issue/issue.json b/erpnext/support/doctype/issue/issue.json
index 529ae89..137b088 100644
--- a/erpnext/support/doctype/issue/issue.json
+++ b/erpnext/support/doctype/issue/issue.json
@@ -105,11 +105,11 @@
   {
    "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
-   "bold": 1, 
+   "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "mins_to_first_response", 
-   "fieldtype": "Float", 
+   "fieldname": "issue_type", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -117,14 +117,15 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Mins to First Response", 
+   "label": "Issue Type", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Issue Type", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 1, 
+   "read_only": 0, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -324,10 +325,10 @@
    "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
-   "collapsible": 0, 
+   "collapsible": 1, 
    "columns": 0, 
-   "fieldname": "column_break_9", 
-   "fieldtype": "Column Break", 
+   "fieldname": "response", 
+   "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -335,6 +336,7 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Response", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -352,12 +354,11 @@
   {
    "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
-   "bold": 0, 
+   "bold": 1, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "eval:!doc.__islocal", 
-   "fieldname": "resolution_date", 
-   "fieldtype": "Datetime", 
+   "fieldname": "mins_to_first_response", 
+   "fieldtype": "Float", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -365,12 +366,11 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Resolution Date", 
+   "label": "Mins to First Response", 
    "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "resolution_date", 
-   "oldfieldtype": "Date", 
+   "no_copy": 0, 
    "permlevel": 0, 
+   "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
@@ -425,7 +425,7 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Contact", 
+   "label": "Reference", 
    "length": 0, 
    "no_copy": 0, 
    "options": "fa fa-pushpin", 
@@ -595,6 +595,36 @@
    "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Company", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Company", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
    "collapsible": 1, 
    "columns": 0, 
    "fieldname": "section_break_19", 
@@ -629,7 +659,7 @@
    "columns": 0, 
    "depends_on": "eval:!doc.__islocal", 
    "fieldname": "resolution_details", 
-   "fieldtype": "Text Editor", 
+   "fieldtype": "Small Text", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -752,8 +782,9 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "company", 
-   "fieldtype": "Link", 
+   "depends_on": "eval:!doc.__islocal", 
+   "fieldname": "resolution_date", 
+   "fieldtype": "Datetime", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -761,14 +792,15 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Company", 
+   "label": "Resolution Date", 
    "length": 0, 
-   "no_copy": 0, 
-   "options": "Company", 
+   "no_copy": 1, 
+   "oldfieldname": "resolution_date", 
+   "oldfieldtype": "Date", 
    "permlevel": 0, 
-   "print_hide": 1, 
+   "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -847,7 +879,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-06-13 14:29:19.581715", 
+ "modified": "2017-11-15 17:15:40.347362", 
  "modified_by": "Administrator", 
  "module": "Support", 
  "name": "Issue", 
diff --git a/erpnext/support/doctype/issue/test_issue.js b/erpnext/support/doctype/issue/test_issue.js
new file mode 100644
index 0000000..c532ea4
--- /dev/null
+++ b/erpnext/support/doctype/issue/test_issue.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Issue", function (assert) {
+	let done = assert.async();
+
+	// number of asserts
+	assert.expect(1);
+
+	frappe.run_serially([
+		// insert a new Issue
+		() => frappe.tests.make('Issue', [
+			// values to be set
+			{key: 'value'}
+		]),
+		() => {
+			assert.equal(cur_frm.doc.key, 'value');
+		},
+		() => done()
+	]);
+
+});
diff --git a/erpnext/support/doctype/issue_type/__init__.py b/erpnext/support/doctype/issue_type/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/support/doctype/issue_type/__init__.py
diff --git a/erpnext/support/doctype/issue_type/issue_type.js b/erpnext/support/doctype/issue_type/issue_type.js
new file mode 100644
index 0000000..2b3d14e
--- /dev/null
+++ b/erpnext/support/doctype/issue_type/issue_type.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Issue Type', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/support/doctype/issue_type/issue_type.json b/erpnext/support/doctype/issue_type/issue_type.json
new file mode 100644
index 0000000..ee7add8
--- /dev/null
+++ b/erpnext/support/doctype/issue_type/issue_type.json
@@ -0,0 +1,115 @@
+{
+ "allow_copy": 0, 
+ "allow_guest_to_view": 0, 
+ "allow_import": 1, 
+ "allow_rename": 0, 
+ "autoname": "Prompt", 
+ "beta": 0, 
+ "creation": "2017-10-06 12:53:34.714153", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Setup", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Description", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "has_web_view": 0, 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2017-11-15 17:27:19.796807", 
+ "modified_by": "Administrator", 
+ "module": "Support", 
+ "name": "Issue Type", 
+ "name_case": "Title Case", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "System Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Support Team", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "search_fields": "", 
+ "show_name_in_global_search": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "title_field": "", 
+ "track_changes": 1, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/support/doctype/issue_type/issue_type.py b/erpnext/support/doctype/issue_type/issue_type.py
new file mode 100644
index 0000000..f95d09c
--- /dev/null
+++ b/erpnext/support/doctype/issue_type/issue_type.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class IssueType(Document):
+	pass
diff --git a/erpnext/support/doctype/issue_type/test_issue_type.js b/erpnext/support/doctype/issue_type/test_issue_type.js
new file mode 100644
index 0000000..9ef737b
--- /dev/null
+++ b/erpnext/support/doctype/issue_type/test_issue_type.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Issue Type", function (assert) {
+	let done = assert.async();
+
+	// number of asserts
+	assert.expect(1);
+
+	frappe.run_serially([
+		// insert a new Issue Type
+		() => frappe.tests.make('Issue Type', [
+			// values to be set
+			{key: 'value'}
+		]),
+		() => {
+			assert.equal(cur_frm.doc.key, 'value');
+		},
+		() => done()
+	]);
+
+});
diff --git a/erpnext/support/doctype/issue_type/test_issue_type.py b/erpnext/support/doctype/issue_type/test_issue_type.py
new file mode 100644
index 0000000..4e3b66a
--- /dev/null
+++ b/erpnext/support/doctype/issue_type/test_issue_type.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+
+class TestIssueType(unittest.TestCase):
+	pass
diff --git a/erpnext/templates/utils.py b/erpnext/templates/utils.py
index 7ee3960..eb84bcc 100644
--- a/erpnext/templates/utils.py
+++ b/erpnext/templates/utils.py
@@ -9,16 +9,16 @@
 
 @frappe.whitelist(allow_guest=True)
 def send_message(subject="Website Query", message="", sender="", status="Open"):
-    from frappe.www.contact import send_message as website_send_message
-    lead = customer = None
+	from frappe.www.contact import send_message as website_send_message
+	lead = customer = None
 
-    website_send_message(subject, message, sender)
+	website_send_message(subject, message, sender)
 
-    customer = frappe.db.sql("""select distinct dl.link_name from `tabDynamic Link` dl 
-        left join `tabContact` c on dl.parent=c.name where dl.link_doctype='Customer' 
-        and c.email_id='{email_id}'""".format(email_id=sender))
+	customer = frappe.db.sql("""select distinct dl.link_name from `tabDynamic Link` dl
+		left join `tabContact` c on dl.parent=c.name where dl.link_doctype='Customer'
+		and c.email_id='{email_id}'""".format(email_id=sender))
 
-    if not customer:
+	if not customer:
 		lead = frappe.db.get_value('Lead', dict(email_id=sender))
 		if not lead:
 			new_lead = frappe.get_doc(dict(
@@ -27,33 +27,33 @@
 				lead_name = sender.split('@')[0].title()
 			)).insert(ignore_permissions=True)
 
-    opportunity = frappe.get_doc(dict(
-    	doctype ='Opportunity',
-    	enquiry_from = 'Customer' if customer else 'Lead',
-    	status = 'Open',
-    	title = subject,
-	contact_email = sender,
-    	to_discuss = message
-    ))
+	opportunity = frappe.get_doc(dict(
+		doctype ='Opportunity',
+		enquiry_from = 'Customer' if customer else 'Lead',
+		status = 'Open',
+		title = subject,
+		contact_email = sender,
+		to_discuss = message
+	))
 
-    if customer:
-        opportunity.customer = customer[0][0]
-    elif lead:
-        opportunity.lead = lead
-    else:
-        opportunity.lead = new_lead.name
+	if customer:
+		opportunity.customer = customer[0][0]
+	elif lead:
+		opportunity.lead = lead
+	else:
+		opportunity.lead = new_lead.name
 
-    opportunity.insert(ignore_permissions=True)
+	opportunity.insert(ignore_permissions=True)
 
-    comm = frappe.get_doc({
-    	"doctype":"Communication",
-    	"subject": subject,
-    	"content": message,
-    	"sender": sender,
-    	"sent_or_received": "Received",
-    	'reference_doctype': 'Opportunity',
-    	'reference_name': opportunity.name
-    })
-    comm.insert(ignore_permissions=True)
+	comm = frappe.get_doc({
+		"doctype":"Communication",
+		"subject": subject,
+		"content": message,
+		"sender": sender,
+		"sent_or_received": "Received",
+		'reference_doctype': 'Opportunity',
+		'reference_name': opportunity.name
+	})
+	comm.insert(ignore_permissions=True)
 
-    return "okay"
+	return "okay"