Code cleanup and improvements requested in PR:21404
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index a99ec70..a6ef494 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -12,7 +12,6 @@
 
 	refresh: function(frm) {
 		erpnext.toggle_naming_series();
-		// frm.cscript.voucher_type(frm.doc);
 		
 		if(frm.doc.docstatus==1) {
 			frm.add_custom_button(__('Ledger'), function() {
@@ -121,37 +120,82 @@
 			}
 		});
 	},
+
 	voucher_type: function(frm){
 		frm.toggle_reqd("cheque_no", frm.doc.voucher_type=="Bank Entry");
 		frm.toggle_reqd("cheque_date", frm.doc.voucher_type=="Bank Entry");
-	},
-	from_template: function(frm){
-		var update_jv_details = function(doc, r) {
-			frappe.model.clear_table(frm.doc, "accounts");
-			$.each(r, function(i, d) {
-				var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
-				row.account = d.account;
-				row.balance = d.balance;
-			});
-			refresh_field("accounts");
+
+		if(!frm.doc.company) return;
+		if(frm.)
+
+		if((!(frm.doc.accounts || []).length) || ((frm.doc.accounts || []).length==1 && !frm.doc.accounts[0].account)) {
+			if(in_list(["Bank Entry", "Cash Entry"], frm.doc.voucher_type)) {
+				return frappe.call({
+					type: "GET",
+					method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account",
+					args: {
+						"account_type": (frm.doc.voucher_type=="Bank Entry" ?
+							"Bank" : (frm.doc.voucher_type=="Cash Entry" ? "Cash" : null)),
+						"company": frm.doc.company
+					},
+					callback: function(r) {
+						if(r.message) {
+							// If default company bank account not set
+							if(!$.isEmptyObject(r.message)){
+								update_jv_details(frm.doc, [r.message]);
+							}
+						}
+					}
+				})
+			} 
+			else if(frm.doc.voucher_type=="Opening Entry") {
+				return frappe.call({
+					type:"GET",
+					method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
+					args: {
+						"company": frm.doc.company
+					},
+					callback: function(r) {
+						frappe.model.clear_table(frm.doc, "accounts");
+						if(r.message) {
+							update_jv_details(frm.doc, r.message);
+						}
+						cur_frm.set_value("is_opening", "Yes")
+					}
+				})
+			}
 		}
-		
+	},
+
+	from_template: function(frm){
 		if (frm.doc.from_template){
 			frappe.db.get_doc("Journal Entry Template", frm.doc.from_template)
-			.then((doc) => {
-				frm.set_value("company",doc.company);
-				frm.set_value("voucher_type", doc.voucher_type);
-				frm.set_value("naming_series", doc.je_naming_series);
-				frm.set_value("is_opening", doc.is_opening);
-				update_jv_details(frm.doc, doc.accounts);
-			})
-			.catch((err)=>{
-				console.log(err);
-			})
+				.then((doc) => {
+					frappe.model.clear_table(frm.doc, "accounts");
+					frm.set_value({
+						"company": doc.company,
+						"voucher_type": doc.voucher_type,
+						"naming_series": doc.naming_series,
+						"is_opening": doc.is_opening
+					})
+					update_jv_details(frm.doc, doc.accounts);
+				})
+				.catch((err)=>{
+					console.log(err);
+				})	
 		}
 	}
 });
 
+var update_jv_details = function(doc, r) {
+	$.each(r, function(i, d) {
+		var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
+		row.account = d.account;
+		row.balance = d.balance;
+	});
+	refresh_field("accounts");
+}
+
 erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
 	onload: function() {
 		this.load_defaults();
@@ -404,56 +448,6 @@
 		cur_frm.pformat.print_heading = __("Journal Entry");
 }
 
-// cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
-// 	cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Entry");
-// 	cur_frm.set_df_property("cheque_date", "reqd", doc.voucher_type=="Bank Entry");
-
-// 	if(!doc.company) return;
-
-// 	var update_jv_details = function(doc, r) {
-// 		$.each(r, function(i, d) {
-// 			var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
-// 			row.account = d.account;
-// 			row.balance = d.balance;
-// 		});
-// 		refresh_field("accounts");
-// 	}
-
-// 	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",
-// 				method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account",
-// 				args: {
-// 					"account_type": (doc.voucher_type=="Bank Entry" ?
-// 						"Bank" : (doc.voucher_type=="Cash Entry" ? "Cash" : null)),
-// 					"company": doc.company
-// 				},
-// 				callback: function(r) {
-// 					if(r.message) {
-// 						update_jv_details(doc, [r.message]);
-// 					}
-// 				}
-// 			})
-// 		} else if(doc.voucher_type=="Opening Entry") {
-// 			return frappe.call({
-// 				type:"GET",
-// 				method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
-// 				args: {
-// 					"company": doc.company
-// 				},
-// 				callback: function(r) {
-// 					frappe.model.clear_table(doc, "accounts");
-// 					if(r.message) {
-// 						update_jv_details(doc, r.message);
-// 					}
-// 					cur_frm.set_value("is_opening", "Yes")
-// 				}
-// 			})
-// 		}
-// 	}
-// }
-
 frappe.ui.form.on("Journal Entry Account", {
 	party: function(frm, cdt, cdn) {
 		var d = frappe.get_doc(cdt, cdn);
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json
index b943452..2335109 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.json
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json
@@ -491,14 +491,17 @@
    "fieldname": "from_template",
    "fieldtype": "Link",
    "label": "From Template",
-   "options": "Journal Entry Template"
+   "no_copy": 1,
+   "options": "Journal Entry Template",
+   "print_hide": 1,
+   "report_hide": 1
   }
  ],
  "icon": "fa fa-file-text",
  "idx": 176,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-04-25 02:02:04.017198",
+ "modified": "2020-04-26 04:48:31.753820",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Journal Entry",
diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js
index 153392d..3dc66aa 100644
--- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js
+++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js
@@ -2,23 +2,26 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on("Journal Entry Template", {
-	// refresh: function(frm) {
-
-	// }
 	setup: function(frm) {
-		frm.set_query("account" ,"accounts", () => {
-				return {
-					filters: {
-						"company": frm.doc.company==undefined ? null: frm.doc.company,
-					}
+		frappe.model.set_default_values(frm.doc);
+		frm.set_query("account" ,"accounts", function(){
+			return {
+				filters: {
+					"company": frm.doc.company,
 				}
+			}
 		});
-	},
-	onload_post_render: function(frm){
-		// frm.get_field("accounts").grid.set_multiple_add("account");
-	},
-	all_accounts: function(frm) {
-		frm.trigger("clear_child");
+		frappe.call({
+			type: "GET",
+			method: "erpnext.accounts.doctype.journal_entry_template.journal_entry_template.get_naming_series",
+			callback: function(r){
+				if(r.message){
+					frm.set_df_property("naming_series", "options", r.message.split("\n"));
+					frm.set_value("naming_series", r.message.split("\n")[0]);
+					frm.refresh_field("naming_series");
+				}
+			}
+		});
 	},
 	voucher_type: function(frm) {
 		var add_accounts = function(doc, r) {
@@ -28,14 +31,13 @@
 			});
 			refresh_field("accounts");
 		}
+	
+		if(!frm.doc.company) return;
+	
 		frm.trigger("clear_child");
 		switch(frm.doc.voucher_type){
 			case "Opening Entry":
-				if(frm.doc.company == undefined){
-					frappe.throw("Please select Company!");
-				}
 				frm.set_value("is_opening", "Yes");
-				
 				frappe.call({
 					type:"GET",
 					method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
@@ -61,10 +63,13 @@
 					},
 					callback: function(r) {
 						if(r.message) {
-							add_accounts(frm.doc, [r.message]);
+							// If default company bank account not set
+							if(!$.isEmptyObject(r.message)){
+								add_accounts(frm.doc, [r.message]);
+							}
 						}
 					}
-				})
+				});
 				break;
 			default:
 				frm.trigger("clear_child");
@@ -72,6 +77,6 @@
 	},
 	clear_child: function(frm){
 		frappe.model.clear_table(frm.doc, "accounts");
-		refresh_field("accounts");
+		frm.refresh_field("accounts");
 	}
-});
+});
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json
index a16503e..3f6cb02 100644
--- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json
+++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json
@@ -1,18 +1,21 @@
 {
  "actions": [],
- "autoname": "naming_series:",
+ "autoname": "field:template_title",
  "creation": "2020-04-09 01:32:51.332301",
  "doctype": "DocType",
+ "document_type": "Document",
  "editable_grid": 1,
  "engine": "InnoDB",
  "field_order": [
   "section_break_1",
-  "voucher_type",
-  "company",
-  "column_break_3",
-  "je_naming_series",
-  "is_opening",
+  "template_title",
   "section_break_2",
+  "company",
+  "voucher_type",
+  "column_break_3",
+  "naming_series",
+  "is_opening",
+  "section_break_3",
   "accounts"
  ],
  "fields": [
@@ -32,8 +35,10 @@
    "fieldname": "company",
    "fieldtype": "Link",
    "in_list_view": 1,
+   "in_standard_filter": 1,
    "label": "Company",
    "options": "Company",
+   "remember_last_selected_value": 1,
    "reqd": 1
   },
   {
@@ -41,12 +46,6 @@
    "fieldtype": "Column Break"
   },
   {
-   "default": "ACC-JV-.YYYY.-",
-   "fieldname": "je_naming_series",
-   "fieldtype": "Data",
-   "label": "Naming Series"
-  },
-  {
    "default": "No",
    "fieldname": "is_opening",
    "fieldtype": "Select",
@@ -61,11 +60,31 @@
    "fieldname": "accounts",
    "fieldtype": "Table",
    "label": "Accounting Entries",
-   "options": "JE Template Account"
+   "options": "Journal Entry Template Account"
+  },
+  {
+   "fieldname": "naming_series",
+   "fieldtype": "Select",
+   "label": "Series",
+   "no_copy": 1,
+   "print_hide": 1,
+   "reqd": 1,
+   "set_only_once": 1
+  },
+  {
+   "fieldname": "template_title",
+   "fieldtype": "Data",
+   "label": "Template Title",
+   "reqd": 1,
+   "unique": 1
+  },
+  {
+   "fieldname": "section_break_3",
+   "fieldtype": "Section Break"
   }
  ],
  "links": [],
- "modified": "2020-04-25 02:14:35.185062",
+ "modified": "2020-04-26 04:29:03.347852",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Journal Entry Template",
@@ -79,18 +98,6 @@
    "print": 1,
    "read": 1,
    "report": 1,
-   "role": "System Manager",
-   "share": 1,
-   "write": 1
-  },
-  {
-   "create": 1,
-   "delete": 1,
-   "email": 1,
-   "export": 1,
-   "print": 1,
-   "read": 1,
-   "report": 1,
    "role": "Accounts User",
    "share": 1,
    "write": 1
@@ -106,9 +113,20 @@
    "role": "Accounts Manager",
    "share": 1,
    "write": 1
+  },
+  {
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Auditor",
+   "share": 1
   }
  ],
+ "search_fields": "voucher_type, company",
  "sort_field": "modified",
  "sort_order": "DESC",
+ "title_field": "template_title",
  "track_changes": 1
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py
index d576832..e0b9cbc 100644
--- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py
+++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py
@@ -5,9 +5,10 @@
 from __future__ import unicode_literals
 import frappe
 from frappe.model.document import Document
-from erpnext.accounts.utils import get_balance_on
 
 class JournalEntryTemplate(Document):
-	def autoname(self):
-		self.name = self.voucher_type + ' - ' + frappe.get_value('Company', self.company, 'abbr')
+	pass
 
+@frappe.whitelist()
+def get_naming_series():
+	return frappe.get_meta("Journal Entry").get_field("naming_series").options
diff --git a/erpnext/projects/doctype/project_template/project_template.json b/erpnext/projects/doctype/project_template/project_template.json
index 8352995..445ad9f 100644
--- a/erpnext/projects/doctype/project_template/project_template.json
+++ b/erpnext/projects/doctype/project_template/project_template.json
@@ -1,130 +1,52 @@
 {
- "allow_copy": 0,
- "allow_events_in_timeline": 0,
- "allow_guest_to_view": 0,
- "allow_import": 0,
- "allow_rename": 0,
+ "actions": [],
  "autoname": "Prompt",
- "beta": 0,
  "creation": "2019-02-18 17:23:11.708371",
- "custom": 0,
- "docstatus": 0,
  "doctype": "DocType",
- "document_type": "",
  "editable_grid": 1,
  "engine": "InnoDB",
+ "field_order": [
+  "project_type",
+  "tasks"
+ ],
  "fields": [
   {
-   "allow_bulk_edit": 0,
-   "allow_in_quick_entry": 0,
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "columns": 0,
    "fieldname": "project_type",
    "fieldtype": "Link",
-   "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": "Project Type",
-   "length": 0,
-   "no_copy": 0,
-   "options": "Project Type",
-   "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,
-   "translatable": 0,
-   "unique": 0
+   "options": "Project Type"
   },
   {
-   "allow_bulk_edit": 0,
-   "allow_in_quick_entry": 0,
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "columns": 0,
    "fieldname": "tasks",
    "fieldtype": "Table",
-   "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": "Tasks",
-   "length": 0,
-   "no_copy": 0,
    "options": "Project Template Task",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "print_hide_if_no_value": 0,
-   "read_only": 0,
-   "remember_last_selected_value": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "translatable": 0,
-   "unique": 0
+   "reqd": 1
   }
  ],
- "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": "2019-02-18 18:01:26.519832",
+ "links": [],
+ "modified": "2020-04-26 02:23:53.990322",
  "modified_by": "Administrator",
  "module": "Projects",
  "name": "Project Template",
- "name_case": "",
  "owner": "Administrator",
  "permissions": [
   {
-   "amend": 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
   }
  ],
  "quick_entry": 1,
- "read_only": 0,
- "read_only_onload": 0,
- "show_name_in_global_search": 0,
  "sort_field": "modified",
  "sort_order": "DESC",
- "track_changes": 1,
- "track_seen": 0,
- "track_views": 0
+ "track_changes": 1
 }
\ No newline at end of file