Merge pull request #6381 from rmehta/lead-source

[enhance] added Lead Source master, fixes #6231
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 13f2f61..ced56d0 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -259,7 +259,6 @@
 	if(!doc.company) return;
 
 	var update_jv_details = function(doc, r) {
-		var jvdetail = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
 		$.each(r, function(i, d) {
 			var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
 			row.account = d.account;
@@ -267,8 +266,8 @@
 		});
 		refresh_field("accounts");
 	}
-
-	if(!(doc.accounts || []).length) {
+	
+	if((!(doc.accounts || []).length) || ((doc.accounts || []).length==1 && !doc.accounts[0].account)) {
 		if(in_list(["Bank Entry", "Cash Entry"], doc.voucher_type)) {
 			return frappe.call({
 				type: "GET",
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
index 56ddd6b..4184d79 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
@@ -15,6 +15,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -40,6 +41,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "{supplier_name}", 
    "fieldname": "title", 
    "fieldtype": "Data", 
@@ -66,6 +68,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "naming_series", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -93,6 +96,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "supplier", 
    "fieldtype": "Link", 
@@ -121,6 +125,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -145,6 +150,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break1", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -171,6 +177,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Today", 
    "fieldname": "transaction_date", 
    "fieldtype": "Date", 
@@ -198,6 +205,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 1, 
@@ -225,6 +233,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "company", 
    "fieldtype": "Link", 
@@ -253,6 +262,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "address_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -278,6 +288,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "supplier_address", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -303,6 +314,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_person", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -328,6 +340,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "address_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -352,6 +365,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_display", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -376,6 +390,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_mobile", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -400,6 +415,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "contact_email", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -425,6 +441,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -450,6 +467,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "currency", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -477,6 +495,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "conversion_rate", 
    "fieldtype": "Float", 
@@ -505,6 +524,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "cb_price_list", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -530,6 +550,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "buying_price_list", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -555,6 +576,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "buying_price_list", 
    "fieldname": "price_list_currency", 
    "fieldtype": "Link", 
@@ -581,6 +603,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "buying_price_list", 
    "fieldname": "plc_conversion_rate", 
    "fieldtype": "Float", 
@@ -607,6 +630,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "ignore_pricing_rule", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -631,6 +655,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -657,6 +682,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -684,6 +710,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_22", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -707,6 +734,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -733,6 +761,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -760,6 +789,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_24", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -783,6 +813,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -809,6 +840,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -836,6 +868,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -862,6 +895,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "taxes_and_charges", 
    "fieldtype": "Link", 
@@ -890,6 +924,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -917,6 +952,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "other_charges_calculation", 
    "fieldtype": "HTML", 
    "hidden": 0, 
@@ -942,6 +978,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -968,6 +1005,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -995,6 +1033,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1022,6 +1061,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1049,6 +1089,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_37", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1073,6 +1114,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_added", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1100,6 +1142,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "taxes_and_charges_deducted", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1127,6 +1170,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "total_taxes_and_charges", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1154,6 +1198,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "discount_amount", 
+   "columns": 0, 
    "fieldname": "section_break_41", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1179,6 +1224,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "Grand Total", 
    "fieldname": "apply_discount_on", 
    "fieldtype": "Select", 
@@ -1206,6 +1252,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1232,6 +1279,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_43", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1256,6 +1304,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "additional_discount_percentage", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -1281,6 +1330,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1307,6 +1357,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_46", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1331,6 +1382,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1358,6 +1410,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "", 
    "fieldname": "base_in_words", 
    "fieldtype": "Data", 
@@ -1385,6 +1438,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base_rounded_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1412,6 +1466,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1436,6 +1491,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grand_total", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1463,6 +1519,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "in_words", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -1490,6 +1547,7 @@
    "bold": 0, 
    "collapsible": 1, 
    "collapsible_depends_on": "terms", 
+   "columns": 0, 
    "fieldname": "terms_section_break", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1516,6 +1574,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "tc_name", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1543,6 +1602,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "terms", 
    "fieldtype": "Text Editor", 
    "hidden": 0, 
@@ -1569,6 +1629,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "printing_settings", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1594,6 +1655,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1621,6 +1683,7 @@
    "allow_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1648,6 +1711,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "language", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -1673,6 +1737,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
+   "columns": 0, 
    "fieldname": "more_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1699,6 +1764,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "status", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -1726,6 +1792,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_57", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1749,6 +1816,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "No", 
    "fieldname": "is_subcontracted", 
    "fieldtype": "Select", 
@@ -1770,6 +1838,59 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "reference", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Reference", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "opportunity", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Opportunity", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Opportunity", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "hide_heading": 0, 
@@ -1784,7 +1905,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-07-08 06:48:04.162164", 
+ "modified": "2016-09-14 05:48:17.443848", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier Quotation", 
diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js
index c9f1ffb..2f1169d 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.js
+++ b/erpnext/crm/doctype/opportunity/opportunity.js
@@ -8,16 +8,47 @@
 	customer: function(frm) {
 		erpnext.utils.get_party_details(frm);
 	},
-	customer_address: function(frm, cdt, cdn){
+
+	customer_address: function(frm, cdt, cdn) {
 		erpnext.utils.get_address_display(frm, 'customer_address', 'address_display', false);
 	},
+
 	contact_person: erpnext.utils.get_contact_details,
+
 	enquiry_from: function(frm) {
 		frm.toggle_reqd("lead", frm.doc.enquiry_from==="Lead");
 		frm.toggle_reqd("customer", frm.doc.enquiry_from==="Customer");
 	},
+
 	refresh: function(frm) {
+		var doc = frm.doc;
 		frm.events.enquiry_from(frm);
+
+		if(doc.status!=="Lost") {
+			if(doc.with_items){
+				frm.add_custom_button(__('Supplier Quotation'),
+					function() {
+						frm.trigger("make_supplier_quotation")
+					}, __("Make"));
+
+				frm.add_custom_button(__('Quotation'),
+					cur_frm.cscript.create_quotation, __("Make"));
+
+				frm.page.set_inner_btn_group_as_primary(__("Make"));
+			}
+
+			if(doc.status!=="Quotation") {
+				frm.add_custom_button(__('Lost'),
+					cur_frm.cscript['Declare Opportunity Lost']);
+			}
+		}
+	},
+
+	make_supplier_quotation: function(frm) {
+		frappe.model.open_mapped_doc({
+			method: "erpnext.crm.doctype.opportunity.opportunity.make_supplier_quotation",
+			frm: cur_frm
+		})
 	}
 })
 
@@ -91,17 +122,6 @@
 			});
 		}
 	}
-
-	if(doc.status!=="Lost") {
-		if(doc.status!=="Quotation") {
-			cur_frm.add_custom_button(__('Lost'),
-				cur_frm.cscript['Declare Opportunity Lost']);
-		}
-
-		cur_frm.add_custom_button(__('Quotation'),
-			cur_frm.cscript.create_quotation);
-	}
-
 }
 
 cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index a2a1be2..8bd3a23 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -232,6 +232,25 @@
 	return doclist
 
 @frappe.whitelist()
+def make_supplier_quotation(source_name, target_doc=None):
+	doclist = get_mapped_doc("Opportunity", source_name, {
+		"Opportunity": {
+			"doctype": "Supplier Quotation",
+			"field_map": {
+				"name": "opportunity"
+			}
+		},
+		"Opportunity Item": {
+			"doctype": "Supplier Quotation Item",
+			"field_map": {
+				"uom": "stock_uom"
+			}
+		}
+	}, target_doc)
+
+	return doclist
+
+@frappe.whitelist()
 def set_multiple_status(names, status):
 	names = json.loads(names)
 	for name in names:
diff --git a/erpnext/docs/user/manual/en/customize-erpnext/articles/index.txt b/erpnext/docs/user/manual/en/customize-erpnext/articles/index.txt
index 6edbd72..f8a81a4 100644
--- a/erpnext/docs/user/manual/en/customize-erpnext/articles/index.txt
+++ b/erpnext/docs/user/manual/en/customize-erpnext/articles/index.txt
@@ -14,3 +14,4 @@
 set-language
 set-precision
 user-restriction
+maximum-numbers-of-fields-in-a-form
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/customize-erpnext/articles/maximum-numbers-of-fields-in-a-form.md b/erpnext/docs/user/manual/en/customize-erpnext/articles/maximum-numbers-of-fields-in-a-form.md
new file mode 100644
index 0000000..7751a3d
--- /dev/null
+++ b/erpnext/docs/user/manual/en/customize-erpnext/articles/maximum-numbers-of-fields-in-a-form.md
@@ -0,0 +1,22 @@
+Sometimes while creating custom fields, you might experienced an error message like below:
+
+> Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
+
+### What it actually means?
+
+In simple terms, it means that you have reached the limit of maximum numbers of fields for the specific form/doctype. So, what is the limit of maximum numbers of fields?
+
+In MySQL, there is a hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact limit depends on several interacting factors.
+
+Every table (regardless of storage engine) has a maximum row size of 65,535 bytes. Storage engines may place additional constraints on this limit, reducing the effective maximum row size.
+
+The maximum row size constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size (65,535 bytes). For example, `utf8mb3` characters require up to 3 bytes per character, so for a `VARCHAR(140)` column, the server must allocate `140 × 3 = 420` bytes per value. Consequently, a table cannot contain more than `65,535 / 420 = 156` such columns.
+
+In Frappe frapework, `VARCHAR(140)` type columns are created based on "Data", "Link", "Select", "Dynamic Link", "Password" and "Read Only" fieldtypes. Hence, you can create approximately 156 such columns in the system.
+
+### Solutions:
+
+To add more fields in the system, you can do some changes.
+
+1. Convert some of the fields to "Text", "Small Text", "Text Editor" or "Code" type field. In MySQL, BLOB and TEXT columns count from one to four plus eight bytes each toward the row-size limit because their contents are stored separately from the rest of the row. So, converting to those fieldtypes will free up some spaces and will allow to add some more fields.
+2. Set smaller value in the "Length" property while creating fields, default value is 140. System sets length of `VARCHAR` based on this property and allocates size for that columns. Hence, smaller Length leads to add more fields.
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/stock/item/index.md b/erpnext/docs/user/manual/en/stock/item/index.md
index 4af8eff..7ca9d4e 100644
--- a/erpnext/docs/user/manual/en/stock/item/index.md
+++ b/erpnext/docs/user/manual/en/stock/item/index.md
@@ -1,4 +1,4 @@
-An Item is your companys' product or a service. The term Item is applicable to your core products as well as your raw materials. It can be a product or service that you buy/sell from your customers/ suppliers. ERPNext allows you to manage all sorts of items like raw-materials, sub-assemblies, finished goods, item variants and service items.
+An Item is your companys' product or a service. The term Item is applicable to things (products or services) you sell as well as raw materials or components of products yet to be produced (before they can be sold to customers). An Item can be a phyical product or a service that you buy/sell from your customers/suppliers. ERPNext allows you to manage all sorts of items like raw-materials, sub-assemblies, finished goods, item variants and service items.
 
 ERPNext is optimized for itemized management of your sales and purchase. If you are in services, you can create an Item for each services that your offer. Completing the Item Master is very essential for successful implementation of ERPNext.
 
diff --git a/erpnext/docs/user/manual/en/stock/item/item-variants.md b/erpnext/docs/user/manual/en/stock/item/item-variants.md
index cee3ab1..cdca6ed 100644
--- a/erpnext/docs/user/manual/en/stock/item/item-variants.md
+++ b/erpnext/docs/user/manual/en/stock/item/item-variants.md
@@ -1,10 +1,10 @@
-A Item Variant is a different version of a Item, such as differing sizes or differing colours.
-Without Item variants, you would have to treat the small, medium and large versions of a t-shirt as three separate Items; 
-Item variants let you treat the small, medium and large versions of a t-shirt as variations of the same Item.
+A Item Variant is a version of a Item, such as differing sizes or differing colours (like a _blue_ t-shirt in size _small_ rather then just a t-shirt).
+Without Item variants, you would have to treat the _small, medium_ and _large_ versions of a t-shirt as three separate Items; 
+Item variants let you treat the _small, medium_ and _large_ versions of a t-shirt as variations of the one Item 't-shirt'.
 
-To use Item Variants in ERPNext, create an Item and check 'Has Variants'
+To use Item Variants in ERPNext, create an Item and check 'Has Variants'.
 
-* The Item shall then be referred as a 'Template'
+* The Item shall then be referred to as a so called 'Template'. Such a Template is not identical to a regular 'Item' any longer. For example it (the Template) can not be used directly in any Transactions (Sales Order, Delivery Note, Purchase Invoice) itself. Only the Variants of an Item (_blue_ t-shirt in size _small)_ can be practically used in such. Therefore it would be ideal to decide whether an item 'Has Variants' or not directly when creating it. 
 
 <img class="screenshot" alt="Has Variants" src="{{docs_base_url}}/assets/img/stock/item-has-variants.png">
 
diff --git a/erpnext/hr/web_form/__init__.py b/erpnext/hr/web_form/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/web_form/__init__.py
diff --git a/erpnext/hr/web_form/job_application/__init__.py b/erpnext/hr/web_form/job_application/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/web_form/job_application/__init__.py
diff --git a/erpnext/hr/web_form/job_application/job_application.js b/erpnext/hr/web_form/job_application/job_application.js
new file mode 100644
index 0000000..699703c
--- /dev/null
+++ b/erpnext/hr/web_form/job_application/job_application.js
@@ -0,0 +1,3 @@
+frappe.ready(function() {
+	// bind events here
+})
\ No newline at end of file
diff --git a/erpnext/hr/web_form/job_application/job_application.json b/erpnext/hr/web_form/job_application/job_application.json
new file mode 100644
index 0000000..2aa6520
--- /dev/null
+++ b/erpnext/hr/web_form/job_application/job_application.json
@@ -0,0 +1,68 @@
+{
+ "allow_comments": 1, 
+ "allow_delete": 0, 
+ "allow_edit": 1, 
+ "allow_multiple": 1, 
+ "creation": "2016-09-10 02:53:16.598314", 
+ "doc_type": "Job Applicant", 
+ "docstatus": 0, 
+ "doctype": "Web Form", 
+ "idx": 0, 
+ "introduction_text": "", 
+ "is_standard": 1, 
+ "login_required": 0, 
+ "modified": "2016-09-13 04:56:29.228762", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "job-application", 
+ "owner": "Administrator", 
+ "published": 1, 
+ "route": "job_application", 
+ "success_message": "Thank you for applying.", 
+ "success_url": "/jobs", 
+ "title": "Job Application", 
+ "web_form_fields": [
+  {
+   "fieldname": "job_title", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "label": "Job Opening", 
+   "options": "", 
+   "read_only": 1, 
+   "reqd": 0
+  }, 
+  {
+   "fieldname": "applicant_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "label": "Applicant Name", 
+   "read_only": 0, 
+   "reqd": 1
+  }, 
+  {
+   "fieldname": "email_id", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "label": "Email Id", 
+   "options": "Email", 
+   "read_only": 0, 
+   "reqd": 1
+  }, 
+  {
+   "fieldname": "cover_letter", 
+   "fieldtype": "Text", 
+   "hidden": 0, 
+   "label": "Cover Letter", 
+   "read_only": 0, 
+   "reqd": 0
+  }, 
+  {
+   "fieldname": "resume_attachment", 
+   "fieldtype": "Attach", 
+   "hidden": 0, 
+   "label": "Resume Attachment", 
+   "read_only": 0, 
+   "reqd": 0
+  }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/hr/web_form/job_application/job_application.py b/erpnext/hr/web_form/job_application/job_application.py
new file mode 100644
index 0000000..2334f8b
--- /dev/null
+++ b/erpnext/hr/web_form/job_application/job_application.py
@@ -0,0 +1,7 @@
+from __future__ import unicode_literals
+
+import frappe
+
+def get_context(context):
+	# do your magic here
+	pass
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
index 8438e07..8d844cd 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
@@ -702,6 +702,32 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "description": "If checked, Will include non-stock items in the Material Requests.", 
+   "fieldname": "create_material_requests_non_stock_request", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Include non-stock items", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
    "default": "1", 
    "depends_on": "", 
    "description": "If checked, all the children of each production item will be included in the Material Requests.", 
@@ -823,4 +849,4 @@
  "read_only_onload": 0, 
  "sort_order": "ASC", 
  "track_seen": 0
-}
\ No newline at end of file
+}
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index fd28b54..8521b5e 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -307,7 +307,7 @@
 		self.get_raw_materials(bom_dict)
 		return self.get_csv()
 
-	def get_raw_materials(self, bom_dict):
+	def get_raw_materials(self, bom_dict,non_stock_item=0):
 		""" Get raw materials considering sub-assembly items
 			{
 				"item_code": [qty_required, description, stock_uom, min_order_qty]
@@ -326,7 +326,7 @@
 					from `tabBOM Explosion Item` fb, `tabBOM` bom, `tabItem` item
 					where bom.name = fb.parent and item.name = fb.item_code
 					and (item.is_sub_contracted_item = 0 or ifnull(item.default_bom, "")="")
-					and item.is_stock_item = 1
+					""" + ("and item.is_stock_item = 1","")[non_stock_item] + """
 					and fb.docstatus<2 and bom.name=%(bom)s
 					group by fb.item_code, fb.stock_uom""", {"bom":bom}, as_dict=1):
 						bom_wise_item_details.setdefault(d.item_code, d)
@@ -334,7 +334,7 @@
 				# Get all raw materials considering SA items as raw materials,
 				# so no childs of SA items
 				bom_wise_item_details = self.get_subitems(bom_wise_item_details, bom,1, \
-					self.use_multi_level_bom,self.only_raw_materials, self.include_subcontracted)
+					self.use_multi_level_bom,self.only_raw_materials, self.include_subcontracted,non_stock_item)
 				
 			for item, item_details in bom_wise_item_details.items():
 				for so_qty in so_wise_qty:
@@ -343,14 +343,14 @@
 						
 		self.make_items_dict(item_list)
 
-	def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs):
+	def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs,non_stock_item=0):
 		for d in frappe.db.sql("""select bom_item.item_code, default_material_request_type,
 			ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty, 
 			item.is_sub_contracted_item as is_sub_contracted, item.default_bom as default_bom
 			from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
 			where bom.name = bom_item.parent and bom.name = %(bom)s and bom_item.docstatus < 2
 			and bom_item.item_code = item.name
-			and item.is_stock_item = 1
+			""" + ("and item.is_stock_item = 1","")[non_stock_item] + """
 			group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1):
 			if (d.default_material_request_type == "Purchase" and not (d.is_sub_contracted \
 				and only_raw and include_sublevel)) or (d.default_material_request_type == \
@@ -399,7 +399,7 @@
 			frappe.throw(_("Please enter Warehouse for which Material Request will be raised"))
 
 		bom_dict = self.get_so_wise_planned_qty()
-		self.get_raw_materials(bom_dict)
+		self.get_raw_materials(bom_dict,self.create_material_requests_non_stock_request)
 
 		if self.item_dict:
 			self.create_material_request()
diff --git a/erpnext/schools/doctype/student_admission/student_admission.js b/erpnext/schools/doctype/student_admission/student_admission.js
index 463e929..48f4c46 100644
--- a/erpnext/schools/doctype/student_admission/student_admission.js
+++ b/erpnext/schools/doctype/student_admission/student_admission.js
@@ -2,7 +2,14 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Student Admission', {
-	refresh: function(frm) {
-
+	program: function(frm) {
+		if (frm.doc.academic_year && frm.doc.program) {
+			frm.doc.route = frappe.model.scrub(frm.doc.program) + "-" + frappe.model.scrub(frm.doc.academic_year)
+			frm.refresh_field("route");
+		}
+	},
+	
+	academic_year: function(frm) {
+		frm.trigger("program");
 	}
 });
diff --git a/erpnext/schools/doctype/student_admission/student_admission.json b/erpnext/schools/doctype/student_admission/student_admission.json
index abd4c93..e757ae1 100644
--- a/erpnext/schools/doctype/student_admission/student_admission.json
+++ b/erpnext/schools/doctype/student_admission/student_admission.json
@@ -95,6 +95,32 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "title", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Title", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "publish", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -163,7 +189,7 @@
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
-   "reqd": 0, 
+   "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -227,6 +253,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "", 
    "fieldname": "route", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -243,6 +270,32 @@
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 1
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "application_form_route", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Application Form Route", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
@@ -336,7 +389,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-15 02:59:15.180465", 
+ "modified": "2016-09-15 07:03:55.581346", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Admission", 
@@ -369,6 +422,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
- "title_field": "program", 
+ "title_field": "title", 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_admission/student_admission.py b/erpnext/schools/doctype/student_admission/student_admission.py
index e0ac983..c4384e2 100644
--- a/erpnext/schools/doctype/student_admission/student_admission.py
+++ b/erpnext/schools/doctype/student_admission/student_admission.py
@@ -10,11 +10,16 @@
 class StudentAdmission(WebsiteGenerator):
 	website = frappe._dict(
 		template = "templates/generators/student_admission.html",
-		condition_field = "publish"
+		condition_field = "publish",
+		page_title_field = "route"
 	)
 
 	def get_context(self, context):
 		context.parents = [{'name': 'admissions', 'title': _('All Student Admissions') }]
+		
+	def validate(self):
+		if not self.title:
+			self.title = self.program + " admissions for " + self.academic_year
 
 def get_list_context(context):
 	context.title = _("Student Admissions")
diff --git a/erpnext/templates/generators/student_admission.html b/erpnext/templates/generators/student_admission.html
index 53c5311..7eb9226 100644
--- a/erpnext/templates/generators/student_admission.html
+++ b/erpnext/templates/generators/student_admission.html
@@ -7,7 +7,7 @@
 
 {% block header %}
 
-<h1>{{ program }}</h1>
+<h1>{{ title }}</h1>
 {% endblock %}
 
 {% block page_content %}
@@ -23,6 +23,10 @@
 
 <table class="table table-bordered" style="margin-top: 20px; width: 30%">
 	<tr>
+		<th> Program</th>
+		<td>{{ program }} </td>
+	</tr>
+	<tr>
 		<th> Academic Year</th>
 		<td>{{ academic_year }} </td>
 	</tr>
@@ -40,10 +44,12 @@
 	</tr>
 </table>
 
+{%- if application_form_route -%}
 <p>
 	<a class='btn btn-primary'
-	href='/student-applicant?program={{ doc.program }}&academic_year={{ doc.academic_year }}&new=1'>
+	href='/{{ doc.application_form_route }}?program={{ doc.program }}&academic_year={{ doc.academic_year }}&new=1'>
 	{{ _("Apply Now") }}</a>
 </p>
+{% endif %}
 
 {% endblock %}