Transaction.js fixed , code commonified
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 3a4ab4a..8c2b1a2 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -2,7 +2,6 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.buying");
-frappe.require("assets/erpnext/js/utils.js");
 
 cur_frm.cscript.tname = "Purchase Order Item";
 cur_frm.cscript.fname = "po_details";
@@ -210,12 +209,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-}
-
-cur_frm.cscript.company = function(doc, cdt, cdn) {
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
-}
-
-cur_frm.cscript.transaction_date = function(doc, cdt, cdn){
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
 }
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
index 13fb4e0..b9286a1 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
@@ -11,8 +11,6 @@
 {% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
 {% include 'accounts/doctype/sales_invoice/pos.js' %}
 
-frappe.require("assets/erpnext/js/utils.js");
-
 erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
 	refresh: function() {
 		this._super();
@@ -73,12 +71,4 @@
 	return {
 		filters:{'supplier': doc.supplier}
 	}
-}
-
-cur_frm.cscript.company = function(doc, cdt, cdn) {
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
-}
-
-cur_frm.cscript.transaction_date = function(doc, cdt, cdn){
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
 }
\ No newline at end of file
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index 8fce8e8..41b3842 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -207,23 +207,33 @@
 	},
 
 	company: function() {
-		if(this.frm.doc.company && this.frm.fields_dict.currency) {
-			var company_currency = this.get_company_currency();
-			if (!this.frm.doc.currency) {
-				this.frm.set_value("currency", company_currency);
-			}
+		var me = this;
+		var fn = function() {
+			if(me.frm.doc.company && me.frm.fields_dict.currency) {
+				var company_currency = me.get_company_currency();
+				if (!me.frm.doc.currency) {
+					me.frm.set_value("currency", company_currency);
+				}
 
-			if (this.frm.doc.currency == company_currency) {
-				this.frm.set_value("conversion_rate", 1.0);
-			}
-			if (this.frm.doc.price_list_currency == company_currency) {
-				this.frm.set_value('plc_conversion_rate', 1.0);
-			}
+				if (me.frm.doc.currency == company_currency) {
+					me.frm.set_value("conversion_rate", 1.0);
+				}
+				if (me.frm.doc.price_list_currency == company_currency) {
+					me.frm.set_value('plc_conversion_rate', 1.0);
+				}
 
-			this.frm.script_manager.trigger("currency");
-			this.apply_pricing_rule();
+				me.frm.script_manager.trigger("currency");
+				me.apply_pricing_rule();
+			}	
 		}
-		erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
+		
+		if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date;
+		else var date = this.frm.doc.transaction_date;
+		erpnext.get_fiscal_year(this.frm.doc.company, date, fn);
+	},
+
+	transaction_date: function() {
+		erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.transaction_date);
 	},
 
 	posting_date: function() {
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 5a0e9d4..f72bcc4 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -12,7 +12,7 @@
 			return frappe.boot.sysdefaults.currency;
 	},
 
-	get_fiscal_year: function(company, date) {
+	get_fiscal_year: function(company, date, fn) {
 		frappe.call({
 			type:"GET",
 			method: "erpnext.accounts.utils.get_fiscal_year",
@@ -23,6 +23,7 @@
 			},
 			callback: function(r) {
 				if (r.message)	cur_frm.set_value("fiscal_year", r.message[0]);
+				if (fn) fn();
 			}
 		});
 	},
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index c00b6e1..857a259 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -12,8 +12,6 @@
 {% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
 {% include 'accounts/doctype/sales_invoice/pos.js' %}
 
-frappe.require("assets/erpnext/js/utils.js");
-
 erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
 	onload: function(doc, dt, dn) {
 		var me = this;
@@ -171,12 +169,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-}
-
-cur_frm.cscript.company = function(doc, cdt, cdn) {
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
-}
-
-cur_frm.cscript.transaction_date = function(doc, cdt, cdn){
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
 }
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 2533735..65b91f4 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -198,12 +198,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-};
-
-cur_frm.cscript.company = function(doc, cdt, cdn) {
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
-}
-
-cur_frm.cscript.transaction_date = function(doc, cdt, cdn){
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 27dd728..147a3b1 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -196,12 +196,4 @@
 cur_frm.cscript.send_sms = function() {
 	frappe.require("assets/erpnext/js/sms_manager.js");
 	var sms_man = new SMSManager(cur_frm.doc);
-}
-
-cur_frm.cscript.company = function(doc, cdt, cdn) {
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
-}
-
-cur_frm.cscript.transaction_date = function(doc, cdt, cdn){
-	erpnext.get_fiscal_year(doc.company, doc.transaction_date);
 }
\ No newline at end of file