[fix] [minor] show stock ledger, general ledger, fixes post changes in script manager trigger [issue] webnotes/wnframework#228
diff --git a/accounts/doctype/journal_voucher/journal_voucher.js b/accounts/doctype/journal_voucher/journal_voucher.js
index a7f5b16..867ebbb 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.js
+++ b/accounts/doctype/journal_voucher/journal_voucher.js
@@ -18,10 +18,20 @@
 
 erpnext.accounts.JournalVoucher = wn.ui.form.Controller.extend({
 	onload: function() {
-		this.load_defaults(this.frm.doc);
+		this.load_defaults();
 		this.setup_queries();
 	},
 	
+	load_defaults: function() {
+		if(this.frm.doc.__islocal && this.frm.doc.company) {
+			wn.model.set_default_values(this.frm.doc);
+			$.each(wn.model.get_doclist(this.frm.doc.doctype, this.frm.doc.name, {parentfield: "entries"}),
+				function(i, jvd) { wn.model.set_default_values(jvd); });
+			
+			this.frm.doc.posting_date = get_today();
+		}
+	},
+	
 	setup_queries: function() {
 		var me = this;
 		
@@ -82,23 +92,6 @@
 	}
 }
 
-cur_frm.cscript.load_defaults = function(doc) {
-	if(!cur_frm.doc.__islocal || !cur_frm.doc.company) { return; }
-
-	doc = locals[doc.doctype][doc.name];
-	var fields_to_refresh = wn.model.set_default_values(doc);
-	if(fields_to_refresh) { refresh_many(fields_to_refresh); }
-
-	fields_to_refresh = null;
-	var children = getchildren('Journal Voucher Detail', doc.name, 'entries');
-	if(!children) { return; }
-	for(var i=0; i<children.length; i++) {
-		wn.model.set_default_values(children[i]);
-	}
-	refresh_field('entries');
-}
-
-
 cur_frm.cscript.is_opening = function(doc, cdt, cdn) {
 	hide_field('aging_date');
 	if (doc.is_opening == 'Yes') unhide_field('aging_date');
diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js
index 4eb68da..aa67506 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -133,6 +133,8 @@
 	},
 	
 	is_pos: function() {
+		cur_frm.cscript.hide_fields(this.frm.doc);
+		
 		if(cint(this.frm.doc.is_pos)) {
 			if(!this.frm.doc.company) {
 				this.frm.set_value("is_pos", 0);
@@ -145,9 +147,6 @@
 				});
 			}
 		}
-		
-		// TODO toggle display of fields
-		cur_frm.cscript.hide_fields(this.frm.doc);
 	},
 	
 	debit_to: function() {
@@ -191,8 +190,7 @@
 // Hide Fields
 // ------------
 cur_frm.cscript.hide_fields = function(doc) {
-	par_flds = ['project_name', 'due_date', 'is_opening', 'conversion_rate',
-	'source', 'total_advance', 'gross_profit',
+	par_flds = ['project_name', 'due_date', 'is_opening', 'source', 'total_advance', 'gross_profit',
 	'gross_profit_percent', 'get_advances_received',
 	'advance_adjustment_details', 'sales_partner', 'commission_rate',
 	'total_commission', 'advances'];
diff --git a/hr/doctype/expense_claim/expense_claim.js b/hr/doctype/expense_claim/expense_claim.js
index 6b60607..243075d 100644
--- a/hr/doctype/expense_claim/expense_claim.js
+++ b/hr/doctype/expense_claim/expense_claim.js
@@ -63,6 +63,12 @@
 			cur_frm.set_value("approval_status", "Draft");
 		cur_frm.cscript.clear_sanctioned(doc);
 	}
+	
+	cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
+		return{
+			query:"controllers.queries.employee_query"
+		}	
+	}
 
 	return cur_frm.call({
 		method:"hr.utils.get_expense_approver_list",
@@ -70,12 +76,6 @@
 			cur_frm.set_df_property("exp_approver", "options", r.message);
 		}
 	});
-	
-	cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
-		return{
-			query:"controllers.queries.employee_query"
-		}	
-	}
 }
 
 cur_frm.cscript.clear_sanctioned = function(doc) {
diff --git a/public/js/complete_setup.js b/public/js/complete_setup.js
index d18bc82..3a6bad5 100644
--- a/public/js/complete_setup.js
+++ b/public/js/complete_setup.js
@@ -54,7 +54,7 @@
 			$('header').toggle(false); // hide toolbar
 		}
 		
-		return wn.call({
+		wn.call({
 			method:"webnotes.country_info.get_country_timezone_info",
 			callback: function(data) {
 				erpnext.country_info = data.message.country_info;
diff --git a/public/js/controllers/stock_controller.js b/public/js/controllers/stock_controller.js
index ccbca4e..e657185 100644
--- a/public/js/controllers/stock_controller.js
+++ b/public/js/controllers/stock_controller.js
@@ -19,22 +19,26 @@
 erpnext.stock.StockController = wn.ui.form.Controller.extend({
 	show_stock_ledger: function() {
 		var me = this;
-		this.frm.add_custom_button("Stock Ledger", function() {
-			wn.route_options = {
-				voucher_no: me.frm.doc.name,
-				from_date: cur_frm.doc.posting_date,
-				to_date: cur_frm.doc.posting_date
-			};
-			wn.set_route('stock-ledger');
-		}, "icon-bar-chart");
+		if(this.frm.doc.docstatus===1) {
+			this.frm.add_custom_button("Stock Ledger", function() {
+				wn.route_options = {
+					voucher_no: me.frm.doc.name,
+					from_date: me.frm.doc.posting_date,
+					to_date: me.frm.doc.posting_date
+				};
+				wn.set_route('stock-ledger');
+			}, "icon-bar-chart");
+		}
+		
 	},
 	show_general_ledger: function() {
-		if(doc.docstatus==1) { 
+		var me = this;
+		if(this.frm.doc.docstatus===1 && cint(wn.defaults.get_default("auto_inventory_accounting"))) { 
 			cur_frm.add_custom_button('Accounting Ledger', function() {
 				wn.route_options = {
-					"voucher_no": doc.name,
-					"from_date": doc.posting_date,
-					"to_date": doc.posting_date,
+					"voucher_no": me.frm.doc.name,
+					"from_date": me.frm.doc.posting_date,
+					"to_date": me.frm.doc.posting_date,
 				};
 				wn.set_route("general-ledger");
 			});
diff --git a/public/js/transaction.js b/public/js/transaction.js
index 2062fe5..2cee843 100644
--- a/public/js/transaction.js
+++ b/public/js/transaction.js
@@ -15,8 +15,9 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 wn.provide("erpnext");
+wn.require("app/js/controllers/stock_controller.js");
 
-erpnext.TransactionController = wn.ui.form.Controller.extend({
+erpnext.TransactionController = erpnext.stock.StockController.extend({
 	onload: function() {
 		if(this.frm.doc.__islocal) {
 			var me = this,
diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js
index 81bc23c..fb5bae5 100644
--- a/selling/doctype/opportunity/opportunity.js
+++ b/selling/doctype/opportunity/opportunity.js
@@ -86,15 +86,15 @@
 	customer: function() {
 		var me = this;
 		if(this.frm.doc.customer) {
-			return this.frm.call({
-				doc: this.frm.doc,
-				method: "set_customer_defaults",
-			});
-			
 			// TODO shift this to depends_on
 			unhide_field(['customer_address', 'contact_person', 'customer_name',
 				'address_display', 'contact_display', 'contact_mobile', 'contact_email', 
 				'territory', 'customer_group']);
+				
+			return this.frm.call({
+				doc: this.frm.doc,
+				method: "set_customer_defaults",
+			});
 		}
 	}, 
 	
diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js
index 93af7cd..08ec6ab 100644
--- a/selling/doctype/quotation/quotation.js
+++ b/selling/doctype/quotation/quotation.js
@@ -114,6 +114,7 @@
 
 cur_frm.cscript.lead = function(doc, cdt, cdn) {
 	if(doc.lead) {
+		unhide_field('territory');
 		return cur_frm.call({
 			doc: cur_frm.doc,
 			method: "set_lead_defaults",
@@ -123,7 +124,6 @@
 				}
 			}
 		});
-		unhide_field('territory');
 	}
 }
 
diff --git a/setup/page/setup/setup.js b/setup/page/setup/setup.js
index ab640cf..40b67d8 100644
--- a/setup/page/setup/setup.js
+++ b/setup/page/setup/setup.js
@@ -21,36 +21,7 @@
 		completed = 0;
 
 	body.html('<div class="progress progress-striped active">\
-		<div class="progress-bar" style="width: 100%;"></div></div>')
-
-	return wn.call({
-		method: "setup.page.setup.setup.get",
-		callback: function(r) {
-			if(r.message) {
-				body.empty();
-				if(wn.boot.expires_on) {
-					$(body).prepend("<div class='text-muted' style='text-align:right'>Account expires on "
-							+ wn.datetime.global_date_format(wn.boot.expires_on) + "</div>");
-				}
-
-				$completed = $('<h4>Setup Completed <span class="completed-percent"></span><h4>\
-					<div class="progress"><div class="progress-bar"></div></div>')
-					.appendTo(body);
-
-				$.each(r.message, function(i, item) {
-					render_item(item)
-				});
-				
-				var completed_percent = cint(flt(completed) / total * 100) + "%";
-				$completed
-					.find(".progress-bar")
-					.css({"width": completed_percent});
-				$(body)
-					.find(".completed-percent")
-					.html("(" + completed_percent + ")");
-			}
-		}
-	});
+		<div class="progress-bar" style="width: 100%;"></div></div>');
 	
 	var render_item = function(item, dependency) {		
 		if(item.type==="Section") {
@@ -68,12 +39,12 @@
 			.appendTo(body);
 
 		$('<div class="col col-lg-1"></div>').appendTo(row);
-			
+		
 		if(item.type==="Link") {
 			var col = $('<div class="col col-lg-5"><b><a href="#'
 				+item.route+'"><i class="'+item.icon+'"></i> '
 				+item.title+'</a></b></div>').appendTo(row);
-			
+		
 		} else {
 			var col = $(repl('<div class="col col-lg-5">\
 					<span class="badge view-link">%(count)s</span>\
@@ -102,12 +73,12 @@
 			col.addClass("col-offset-1");
 		else
 			$('<div class="col col-lg-1"></div>').appendTo(row);
-			
+		
 		if(item.doctype) {
 			var badge = col.find(".badge, .data-link")
 				.attr("data-doctype", item.doctype)
 				.css({"cursor": "pointer"})
-				
+			
 			if(item.single) {
 				badge.click(function() {
 					wn.set_route("Form", $(this).attr("data-doctype"))
@@ -118,10 +89,10 @@
 				})
 			}
 		}
-		
+	
 		// tree
 		$links = $('<div class="col col-lg-5">').appendTo(row);
-		
+	
 		if(item.tree) {
 			$('<a class="view-link"><i class="icon-sitemap"></i> Browse</a>\
 				<span class="text-muted">|</span> \
@@ -134,7 +105,7 @@
 			mylink.click(function() {
 				wn.set_route(item.tree, item.doctype);
 			})
-						
+					
 		} else if(item.single) {
 			$('<a class="view-link"><i class="icon-edit"></i> Edit</a>')
 				.appendTo($links)
@@ -183,7 +154,7 @@
 				wn.route_options = {doctype:$(this).attr("data-doctype")}
 				wn.set_route("data-import-tool");
 			})
-			
+		
 		if(item.links) {
 			$.each(item.links, function(i, link) {
 				var newlinks = $('<span class="text-muted"> |</span> \
@@ -192,11 +163,40 @@
 					.appendTo($links)
 			})
 		}
-			
+		
 		if(item.dependencies) {
 			$.each(item.dependencies, function(i, d) {
 				render_item(d, true);
 			})
 		}
 	}
+
+	return wn.call({
+		method: "setup.page.setup.setup.get",
+		callback: function(r) {
+			if(r.message) {
+				body.empty();
+				if(wn.boot.expires_on) {
+					$(body).prepend("<div class='text-muted' style='text-align:right'>Account expires on "
+							+ wn.datetime.global_date_format(wn.boot.expires_on) + "</div>");
+				}
+
+				$completed = $('<h4>Setup Completed <span class="completed-percent"></span><h4>\
+					<div class="progress"><div class="progress-bar"></div></div>')
+					.appendTo(body);
+
+				$.each(r.message, function(i, item) {
+					render_item(item)
+				});
+				
+				var completed_percent = cint(flt(completed) / total * 100) + "%";
+				$completed
+					.find(".progress-bar")
+					.css({"width": completed_percent});
+				$(body)
+					.find(".completed-percent")
+					.html("(" + completed_percent + ")");
+			}
+		}
+	});
 }
\ No newline at end of file
diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js
index 88a9840..c5ae431 100644
--- a/stock/doctype/delivery_note/delivery_note.js
+++ b/stock/doctype/delivery_note/delivery_note.js
@@ -36,6 +36,8 @@
 
 		if (doc.docstatus==1) {
 			cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
+			this.show_stock_ledger();
+			this.show_general_ledger();
 		}
 
 		if(doc.docstatus==0 && !doc.__islocal) {
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js
index a134da1..8705143 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -33,6 +33,9 @@
 					this.make_purchase_invoice);
 			}
 			cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
+			
+			this.show_stock_ledger();
+			this.show_general_ledger();
 		}
 
 		cur_frm.add_custom_button(wn._('From Purchase Order'), 
@@ -68,6 +71,10 @@
 		var item = wn.model.get_doc(cdt, cdn);
 		wn.model.round_floats_in(item, ["qty", "received_qty"]);
 		
+		if(!(item.received_qty || item.rejected_qty) && item.qty) {
+			item.received_qty = item.qty;
+		}
+		
 		if(item.qty > item.received_qty) {
 			msgprint(wn._("Error") + ": " + wn._(wn.meta.get_label(item.doctype, "qty", item.name))
 				+ " > " + wn._(wn.meta.get_label(item.doctype, "received_qty", item.name)));
diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js
index 9e8c9a6..4ade2ff 100644
--- a/stock/doctype/stock_entry/stock_entry.js
+++ b/stock/doctype/stock_entry/stock_entry.js
@@ -25,8 +25,8 @@
 	set_default_account: function() {
 		var me = this;
 		
-		if (sys_defaults.auto_inventory_accounting && !this.frm.doc.expense_adjustment_account) {
-			if (this.frm.doc.purpose == "Sales Return") 
+		if (cint(wn.defaults.get_default("auto_inventory_accounting")) && !this.frm.doc.expense_adjustment_account) {
+			if (this.frm.doc.purpose == "Sales Return")
 				account_for = "stock_in_hand_account";
 			else if (this.frm.doc.purpose == "Purchase Return") 
 				account_for = "stock_received_but_not_billed";
@@ -78,7 +78,7 @@
 			}
 		};
 		
-		if (sys_defaults.auto_inventory_accounting) {
+		if(cint(wn.defaults.get_default("auto_inventory_accounting"))) {
 			this.frm.add_fetch("company", "stock_adjustment_account", "expense_adjustment_account");
 
 			this.frm.fields_dict["expense_adjustment_account"].get_query = function() {
@@ -105,11 +105,8 @@
 		erpnext.hide_naming_series();
 		this.toggle_related_fields(this.frm.doc);
 		this.toggle_enable_bom();
-		if (this.frm.doc.docstatus==1) {
-			this.show_stock_ledger();
-			if(wn.boot.auto_inventory_accounting)
-				this.show_general_ledger();
-		}
+		this.show_stock_ledger();
+		this.show_general_ledger();
 		
 		if(this.frm.doc.docstatus === 1 && 
 				wn.boot.profile.can_create.indexOf("Journal Voucher")!==-1) {
diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.js b/stock/doctype/stock_reconciliation/stock_reconciliation.js
index 501b5af..2db8cba 100644
--- a/stock/doctype/stock_reconciliation/stock_reconciliation.js
+++ b/stock/doctype/stock_reconciliation/stock_reconciliation.js
@@ -68,6 +68,7 @@
 		} else if(this.frm.doc.docstatus == 1) {
 			this.frm.set_intro("Cancelling this Stock Reconciliation will nullify its effect.");
 			this.show_stock_ledger();
+			this.show_general_ledger();
 		} else {
 			this.frm.set_intro("");
 		}
diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js
index 4f45220..9535fba 100644
--- a/support/doctype/customer_issue/customer_issue.js
+++ b/support/doctype/customer_issue/customer_issue.js
@@ -26,13 +26,13 @@
 	customer: function() {
 		var me = this;
 		if(this.frm.doc.customer) {
+			// TODO shift this to depends_on
+			unhide_field(['customer_address', 'contact_person']);
+			
 			return this.frm.call({
 				doc: this.frm.doc,
 				method: "set_customer_defaults",
 			});
-			
-			// TODO shift this to depends_on
-			unhide_field(['customer_address', 'contact_person']);
 		}
 	}, 
 	
diff --git a/support/doctype/maintenance_visit/maintenance_visit.js b/support/doctype/maintenance_visit/maintenance_visit.js
index f4e4a35..4257afa 100644
--- a/support/doctype/maintenance_visit/maintenance_visit.js
+++ b/support/doctype/maintenance_visit/maintenance_visit.js
@@ -62,13 +62,13 @@
 	customer: function() {
 		var me = this;
 		if(this.frm.doc.customer) {
+			// TODO shift this to depends_on
+			cur_frm.cscript.hide_contact_info();
+			
 			return this.frm.call({
 				doc: this.frm.doc,
 				method: "set_customer_defaults",
 			});
-			
-			// TODO shift this to depends_on
-			cur_frm.cscript.hide_contact_info();			
 		}
 	}, 
 });
diff --git a/website/templates/js/product_page.js b/website/templates/js/product_page.js
index 97d8f3d..adfeb5e 100644
--- a/website/templates/js/product_page.js
+++ b/website/templates/js/product_page.js
@@ -18,7 +18,7 @@
 	var item_code = $('[itemscope] [itemprop="name"]').text().trim();
 	var qty = 0;
 	
-	return wn.call({
+	wn.call({
 		type: "POST",
 		method: "website.helpers.product.get_product_info",
 		args: {