Merge pull request #2572 from neilLasrado/credit-note

journal entry linked with Stock Entry
diff --git a/.travis.yml b/.travis.yml
index 34a77a9..c5eda1a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,6 +15,7 @@
   - cd ~/ && bench init frappe-bench --frappe-path https://github.com/frappe/frappe.git
   - cp -r $TRAVIS_BUILD_DIR/test_sites/test_site ~/frappe-bench/sites/
 
+<<<<<<< HEAD
 script:
   - cd ~/frappe-bench
   - bench get-app erpnext $TRAVIS_BUILD_DIR
@@ -23,6 +24,13 @@
   - bench frappe --build_website
   - bench frappe --serve_test &
   - bench frappe --verbose --run_tests
+=======
+  - sudo apt-get install xfonts-75dpi xfonts-base -y
+  - wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2/wkhtmltox-0.12.2_linux-precise-amd64.deb
+  - sudo dpkg -i wkhtmltox-0.12.2_linux-precise-amd64.deb
+  - CFLAGS=-O0 pip install git+https://github.com/frappe/frappe.git@develop
+  - CFLAGS=-O0 pip install --editable .
+>>>>>>> da975f5a76aacc24abb71c4a26cb204f9ec72610
 
 before_script:
   - mysql -e 'create database test_frappe'
diff --git a/README.md b/README.md
index b9d5a6e..efa3e33 100644
--- a/README.md
+++ b/README.md
@@ -1,34 +1,31 @@
-# ERPNext - Open Source ERP for small, medium sized businesses [![Build Status](https://travis-ci.org/frappe/erpnext.png)](https://travis-ci.org/frappe/erpnext)
+# ERPNext - Open source ERP for small and medium-size business [![Build Status](https://travis-ci.org/frappe/erpnext.png)](https://travis-ci.org/frappe/erpnext)
 
 [https://erpnext.com](https://erpnext.com)
 
-Includes Accounting, Inventory, CRM, Sales, Purchase, Projects, HRMS. Built on Python / MariaDB.
+Includes: Accounting, Inventory, CRM, Sales, Purchase, Projects, HRMS. Requires MariaDB.
 
-ERPNext is built on [frappe](https://github.com/frappe/frappe) Python Framework.
+ERPNext is built on the [Frappe](https://github.com/frappe/frappe) Framework, a full-stack web app framework in Python & Javascript.
 
-- [User Guide](http://erpnext.org/user-guide.html)
+- [User Guide](https://erpnext.com/user-guide)
 - [Getting Help](http://erpnext.org/getting-help.html)
-- [Developer Forum](http://groups.google.com/group/erpnext-developer-forum)
-- [User Forum](http://groups.google.com/group/erpnext-user-forum)
+- [Discussion Forum](https://discuss.frappe.io/)
 
 ---
 
-### Install
+### Full Install
 
-Use the bench, https://github.com/frappe/bench
+The Easy Way install script for bench will install all dependencies (e.g. MariaDB). See https://github.com/frappe/bench
 
-### Admin Login
+New passwords will be created for the ERPNext "Administrator" user, the MariaDB root user, and the frappe user (the script displays the passwords and saves them to ~/frappe_passwords.txt).
 
-1. go to "/login"
-1. Administrator user name: "Administrator"
-1. Administrator password: "admin"
+### Virtual Image
 
-### Download and Install
-
-##### Virtual Image:
+You can download a virtual image to run ERPNext in a virtual machine on your local system.
 
 - [ERPNext Download](http://erpnext.com/download)
 
+System and user credentials are listed on the download page.
+
 ---
 
 ## License
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 5cfa971..07e93b6 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -230,7 +230,7 @@
 		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;
+			row.account = d.cash_bank_account;
 			row.balance = d.balance;
 		});
 		refresh_field("accounts");
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 9308a3d..9930d8d 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -452,12 +452,20 @@
 			frappe.throw(_("{0} already made against stock entry {1}".format(self.voucher_type, self.stock_entry)))
 
 @frappe.whitelist()
-def get_default_bank_cash_account(company, voucher_type):
-	account = frappe.db.get_value("Company", company,
-		voucher_type=="Bank Entry" and "default_bank_account" or "default_cash_account")
+def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
+	from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
+	if mode_of_payment:
+		account = get_bank_cash_account(mode_of_payment, company)
+		if account.get("bank_cash_account"):
+			account.update({"balance": get_balance_on(account.get("cash_bank_account"))})
+			return account
+
+	account = frappe.db.get_value("Company", company, \
+		voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
+
 	if account:
 		return {
-			"account": account,
+			"cash_bank_account": account,
 			"balance": get_balance_on(account)
 		}
 
@@ -514,7 +522,7 @@
 	d2 = jv.append("accounts")
 
 	if bank_account:
-		d2.account = bank_account["account"]
+		d2.account = bank_account["cash_bank_account"]
 		d2.balance = bank_account["balance"]
 
 	return jv
diff --git a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js
index a86da0e..ffd8ea7 100644
--- a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js
+++ b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.js
@@ -1,7 +1,7 @@
 // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-cur_frm.set_query("default_account", function(doc) {
+cur_frm.set_query("default_account", "mode_of_payment_details", function(doc, cdt, cdn) {
 	return{
 		filters: [
 			['Account', 'account_type', 'in', 'Bank, Cash'],
diff --git a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json
index d1f1677..8a1f5e1 100644
--- a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json
+++ b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.json
@@ -19,29 +19,17 @@
    "reqd": 1
   }, 
   {
-   "fieldname": "company", 
-   "fieldtype": "Link", 
-   "in_list_view": 1, 
-   "label": "Company", 
-   "options": "Company", 
+   "fieldname": "accounts", 
+   "fieldtype": "Table", 
+   "label": "Accounts", 
+   "options": "Mode of Payment Account", 
    "permlevel": 0, 
-   "read_only": 0
-  }, 
-  {
-   "description": "Default Bank / Cash account will be automatically updated in POS Invoice when this mode is selected.", 
-   "fieldname": "default_account", 
-   "fieldtype": "Link", 
-   "ignore_user_permissions": 1, 
-   "in_list_view": 1, 
-   "label": "Default Account", 
-   "options": "Account", 
-   "permlevel": 0, 
-   "read_only": 0
+   "precision": ""
   }
  ], 
  "icon": "icon-credit-card", 
  "idx": 1, 
- "modified": "2015-01-05 11:13:54.446006", 
+ "modified": "2015-01-06 17:21:12.485997", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Mode of Payment", 
diff --git a/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py b/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py
new file mode 100644
index 0000000..2008f98
--- /dev/null
+++ b/erpnext/accounts/doctype/mode_of_payment/test_mode_of_payment.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and Contributors
+# See license.txt
+
+import frappe
+import unittest
+
+test_records = frappe.get_test_records('Mode of Payment')
+
+class TestModeofPayment(unittest.TestCase):
+	pass
diff --git a/erpnext/accounts/doctype/mode_of_payment/test_records.json b/erpnext/accounts/doctype/mode_of_payment/test_records.json
new file mode 100644
index 0000000..f1ff01c
--- /dev/null
+++ b/erpnext/accounts/doctype/mode_of_payment/test_records.json
@@ -0,0 +1,6 @@
+[
+	{
+		"doctype": "Mode of Payment",
+		"name": "_Test Mode of Payment 1"
+	}
+]
diff --git a/erpnext/accounts/doctype/mode_of_payment_account/__init__.py b/erpnext/accounts/doctype/mode_of_payment_account/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/mode_of_payment_account/__init__.py
diff --git a/erpnext/accounts/doctype/mode_of_payment_account/mode_of_payment_account.json b/erpnext/accounts/doctype/mode_of_payment_account/mode_of_payment_account.json
new file mode 100644
index 0000000..bfe961f
--- /dev/null
+++ b/erpnext/accounts/doctype/mode_of_payment_account/mode_of_payment_account.json
@@ -0,0 +1,71 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "creation": "2015-01-05 14:17:53.101432", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Company", 
+   "no_copy": 0, 
+   "options": "Company", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "description": "Default Bank / Cash account will be automatically updated in POS Invoice when this mode is selected.", 
+   "fieldname": "default_account", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Default Account", 
+   "no_copy": 0, 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 1, 
+ "modified": "2015-01-06 17:26:57.053474", 
+ "modified_by": "Administrator", 
+ "module": "Accounts", 
+ "name": "Mode of Payment Account", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [], 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC"
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/mode_of_payment_account/mode_of_payment_account.py b/erpnext/accounts/doctype/mode_of_payment_account/mode_of_payment_account.py
new file mode 100644
index 0000000..933d0a2
--- /dev/null
+++ b/erpnext/accounts/doctype/mode_of_payment_account/mode_of_payment_account.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class ModeofPaymentAccount(Document):
+	pass
diff --git a/erpnext/accounts/doctype/payment_tool/payment_tool.js b/erpnext/accounts/doctype/payment_tool/payment_tool.js
index fd6867a..0cb51d3 100644
--- a/erpnext/accounts/doctype/payment_tool/payment_tool.js
+++ b/erpnext/accounts/doctype/payment_tool/payment_tool.js
@@ -63,7 +63,22 @@
 });
 
 // Fetch bank/cash account based on payment mode
-cur_frm.add_fetch("payment_mode", "default_account", "payment_account");
+frappe.ui.form.on("Payment Tool", "payment_mode", function(frm) {
+	return  frappe.call({
+		method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
+		args: {
+				"mode_of_payment": frm.doc.mode_of_payment,
+				"company": frm.doc.company
+		},
+		callback: function(r, rt) {
+			if(r.message) {
+				frm.doc.set_value("payment_account", r.message['bank_cash_account']
+);
+			}
+		}
+	});
+});
+
 
 erpnext.payment_tool.check_mandatory_to_set_button = function(frm) {
 	if (frm.doc.company && frm.doc.party_type && frm.doc.party && frm.doc.received_or_paid) {
diff --git a/erpnext/accounts/doctype/pos_setting/pos_setting.json b/erpnext/accounts/doctype/pos_setting/pos_setting.json
index 420263b..6b42098 100755
--- a/erpnext/accounts/doctype/pos_setting/pos_setting.json
+++ b/erpnext/accounts/doctype/pos_setting/pos_setting.json
@@ -1,5 +1,6 @@
 {
- "autoname": "POS/.####", 
+ "allow_rename": 0, 
+ "autoname": "hash", 
  "creation": "2013-05-24 12:15:51", 
  "docstatus": 0, 
  "doctype": "DocType", 
@@ -225,7 +226,7 @@
  ], 
  "icon": "icon-cog", 
  "idx": 1, 
- "modified": "2015-01-06 02:20:25.431768", 
+ "modified": "2015-01-15 15:27:41.530538", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "POS Setting", 
@@ -256,5 +257,6 @@
   }
  ], 
  "sort_field": "modified", 
- "sort_order": "DESC"
+ "sort_order": "DESC", 
+ "title_field": "user"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index d0822b6..10daafa 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -169,7 +169,7 @@
    "search_index": 1
   }, 
   {
-   "fieldname": "currency_price_list", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -880,7 +880,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-01-06 17:07:12.151596", 
+ "modified": "2015-01-15 07:34:54.049667", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice", 
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index ff39939..fac9442 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -246,11 +246,15 @@
 
 
 cur_frm.cscript.mode_of_payment = function(doc) {
-	console.log("mode of payment!");
-	return cur_frm.call({
-		method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
-		args: { mode_of_payment: doc.mode_of_payment },
-	});
+	if(doc.is_pos) {
+		return cur_frm.call({
+			method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
+			args: { 
+				"mode_of_payment": doc.mode_of_payment,
+				"company": doc.company
+			 },
+		});
+	 }
 }
 
 cur_frm.cscript.update_stock = function(doc, dt, dn) {
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index ef41c22..b4529bc 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -190,7 +190,7 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "currency_section", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -423,6 +423,15 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "other_charges_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Total Taxes and Charges", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Total Taxes and Charges (Company Currency)", 
@@ -439,23 +448,24 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "other_charges_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Total Taxes and Charges", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0, 
    "print_hide": 0
   }, 
   {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "label": "Totals", 
@@ -1192,7 +1202,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-01-06 11:55:32.975513", 
+ "modified": "2015-01-15 07:33:52.971354", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice", 
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 2de2c10..63aef26 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -577,14 +577,16 @@
 				)
 
 @frappe.whitelist()
-def get_bank_cash_account(mode_of_payment):
-	val = frappe.db.get_value("Mode of Payment", mode_of_payment, "default_account")
-	if not val:
+def get_bank_cash_account(mode_of_payment, company):
+	account = frappe.db.get_value("Mode of Payment Account", {"parent": mode_of_payment, "company": company}, \
+		"default_account")
+	if not account:
 		frappe.msgprint(_("Please set default Cash or Bank account in Mode of Payment {0}").format(mode_of_payment))
 	return {
-		"cash_bank_account": val
+		"cash_bank_account": account
 	}
 
+
 @frappe.whitelist()
 def get_income_account(doctype, txt, searchfield, start, page_len, filters):
 	from erpnext.controllers.queries import get_match_cond
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
index c373796..ae77fe8 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
@@ -46,17 +46,17 @@
 		var new_val = flt(val)/flt(doc.conversion_rate);
 		return new_val;
 	}
-	
+
 	function print_hide(fieldname) {
 		var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
 		return doc_field.print_hide;
 	}
-	
+
 	out ='';
 	if (!doc.print_without_amount) {
 		var cl = doc.taxes || [];
 
-		// outer table	
+		// outer table
 		var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
 
 		// main table
@@ -77,12 +77,12 @@
 
 		// Discount Amount
 		if(!print_hide('discount_amount') && doc.discount_amount)
-			out += make_row('Discount Amount', convert_rate(doc.discount_amount), 0);
+			out += make_row('Discount Amount', doc.discount_amount, 0);
 
 		// grand total
 		if(!print_hide('grand_total_export'))
 			out += make_row('Grand Total', doc.grand_total_export, 1);
-		
+
 		if(!print_hide('rounded_total_export'))
 			out += make_row('Rounded Total', doc.rounded_total_export, 1);
 
@@ -92,7 +92,7 @@
 			out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
 			out += '<td style="width:50%;">' + doc.in_words_export + '</td></tr>';
 		}
-		out += '</table></td></tr></table></div>';	 
+		out += '</table></td></tr></table></div>';
 	}
 	return out;
 }
@@ -139,14 +139,14 @@
 			"account_type": ["Tax", "Chargeable", "Income Account"],
 			"company": doc.company
 		}
-	}	
+	}
 }
 
 cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
 	return{
 		'company': doc.company,
 		'group_or_ledger': "Ledger"
-	}	
+	}
 }
 
 cur_frm.cscript.rate = function(doc, cdt, cdn) {
diff --git a/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json b/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json
index 2b45a58..9421d45 100755
--- a/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json
+++ b/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json
@@ -1,15 +1,15 @@
 {
- "creation": "2012-04-11 13:16:56", 
- "doc_type": "Journal Entry", 
- "docstatus": 0, 
- "doctype": "Print Format", 
- "html": "<div style=\"position: relative\">\n\n\t{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Advice\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n{%- for label, value in (\n        (_(\"Voucher Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Reference / Cheque No.\"), doc.cheque_no),\n        (_(\"Reference / Cheque Date\"), frappe.utils.formatdate(doc.cheque_date))\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-sm-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-8\">{{ value }}</div>\n    </div>\n{%- endfor -%}\n\t<hr>\n\t<p>{{ _(\"This amount is in full / part settlement of the listed bills\") }}:</p>\n{%- for label, value in (\n         (_(\"Amount\"), \"<strong>\" + doc.get_formatted(\"total_amount\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"References\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-sm-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-8\">{{ value }}</div>\n    </div>\n    {%- endfor -%}\n    <hr>\n\t<div style=\"position: absolute; top: 14cm; left: 0cm;\">\n\t\tPrepared By</div>\n\t<div style=\"position: absolute; top: 14cm; left: 5.5cm;\">\n\t\tAuthorised Signatory</div>\n\t<div style=\"position: absolute; top: 14cm; left: 11cm;\">\n\t\tReceived Payment as Above</div>\n\t<div style=\"position: absolute; top: 16.4cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 6cm;\">\n\t\t<strong>A/C Payee</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.9cm; left: 12cm;\">\n\t\t{{ frappe.utils.formatdate(doc.cheque_date) }}</div>\n\t<div style=\"position: absolute; top: 17.9cm; left: 1cm;\">\n\t\t{{ doc.pay_to_recd_from }}</div>\n\t<div style=\"position: absolute; top: 18.6cm; left: 1cm; width: 7cm;\">\n\t\t{{ doc.total_amount_in_words }}</div>\n\t<div style=\"position: absolute; top: 19.7cm; left: 12cm;\">\n\t\t{{ doc.total_amount }}</div>\n</div>", 
- "idx": 1, 
- "modified": "2014-12-12 16:29:57.723432", 
- "modified_by": "Administrator", 
- "module": "Accounts", 
- "name": "Cheque Printing Format", 
- "owner": "Administrator", 
- "print_format_type": "Server", 
+ "creation": "2012-04-11 13:16:56",
+ "doc_type": "Journal Entry",
+ "docstatus": 0,
+ "doctype": "Print Format",
+ "html": "<div style=\"position: relative\">\n\n\t{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Advice\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n{%- for label, value in (\n        (_(\"Voucher Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Reference / Cheque No.\"), doc.cheque_no),\n        (_(\"Reference / Cheque Date\"), frappe.utils.formatdate(doc.cheque_date))\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-xs-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-8\">{{ value }}</div>\n    </div>\n{%- endfor -%}\n\t<hr>\n\t<p>{{ _(\"This amount is in full / part settlement of the listed bills\") }}:</p>\n{%- for label, value in (\n         (_(\"Amount\"), \"<strong>\" + doc.get_formatted(\"total_amount\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"References\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-xs-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-8\">{{ value }}</div>\n    </div>\n    {%- endfor -%}\n    <hr>\n\t<div style=\"position: absolute; top: 14cm; left: 0cm;\">\n\t\tPrepared By</div>\n\t<div style=\"position: absolute; top: 14cm; left: 5.5cm;\">\n\t\tAuthorised Signatory</div>\n\t<div style=\"position: absolute; top: 14cm; left: 11cm;\">\n\t\tReceived Payment as Above</div>\n\t<div style=\"position: absolute; top: 16.4cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 6cm;\">\n\t\t<strong>A/C Payee</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.9cm; left: 12cm;\">\n\t\t{{ frappe.utils.formatdate(doc.cheque_date) }}</div>\n\t<div style=\"position: absolute; top: 17.9cm; left: 1cm;\">\n\t\t{{ doc.pay_to_recd_from }}</div>\n\t<div style=\"position: absolute; top: 18.6cm; left: 1cm; width: 7cm;\">\n\t\t{{ doc.total_amount_in_words }}</div>\n\t<div style=\"position: absolute; top: 19.7cm; left: 12cm;\">\n\t\t{{ doc.total_amount }}</div>\n</div>",
+ "idx": 1,
+ "modified": "2015-01-12 11:03:17.032512",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Cheque Printing Format",
+ "owner": "Administrator",
+ "print_format_type": "Server",
  "standard": "Yes"
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/print_format/credit_note/credit_note.json b/erpnext/accounts/print_format/credit_note/credit_note.json
index 27ed128..de405e6 100644
--- a/erpnext/accounts/print_format/credit_note/credit_note.json
+++ b/erpnext/accounts/print_format/credit_note/credit_note.json
@@ -1,19 +1,19 @@
 {
- "creation": "2014-08-28 11:11:39.796473", 
- "disabled": 0, 
- "doc_type": "Journal Entry", 
- "docstatus": 0, 
- "doctype": "Print Format", 
- "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Credit Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Credit To\"), doc.pay_to_recd_from),\n        (_(\"Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Amount\"), \"<strong>\" + doc.get_formatted(\"total_amount\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n\n    <div class=\"row\">\n        <div class=\"col-sm-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n\n", 
- "idx": 2, 
- "modified": "2014-12-12 16:30:53.890457", 
- "modified_by": "Administrator", 
- "module": "Accounts", 
- "name": "Credit Note", 
- "owner": "Administrator", 
- "parent": "Journal Entry", 
- "parentfield": "__print_formats", 
- "parenttype": "DocType", 
- "print_format_type": "Server", 
+ "creation": "2014-08-28 11:11:39.796473",
+ "disabled": 0,
+ "doc_type": "Journal Entry",
+ "docstatus": 0,
+ "doctype": "Print Format",
+ "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Credit Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Credit To\"), doc.pay_to_recd_from),\n        (_(\"Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Amount\"), \"<strong>\" + doc.get_formatted(\"total_amount\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n\n    <div class=\"row\">\n        <div class=\"col-xs-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n\n",
+ "idx": 2,
+ "modified": "2015-01-12 11:02:25.716825",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Credit Note",
+ "owner": "Administrator",
+ "parent": "Journal Entry",
+ "parentfield": "__print_formats",
+ "parenttype": "DocType",
+ "print_format_type": "Server",
  "standard": "Yes"
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json b/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json
index a1b377a..d5a1e62 100755
--- a/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json
+++ b/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json
@@ -1,15 +1,15 @@
 {
- "creation": "2012-05-01 12:46:31", 
- "doc_type": "Journal Entry", 
- "docstatus": 0, 
- "doctype": "Print Format", 
- "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Receipt Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Received On\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Received From\"), doc.pay_to_recd_from),\n        (_(\"Amount\"), \"<strong>\" + doc.get_formatted(\"total_amount\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-sm-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n", 
- "idx": 1, 
- "modified": "2014-12-12 16:31:33.869069", 
- "modified_by": "Administrator", 
- "module": "Accounts", 
- "name": "Payment Receipt Voucher", 
- "owner": "Administrator", 
- "print_format_type": "Server", 
+ "creation": "2012-05-01 12:46:31",
+ "doc_type": "Journal Entry",
+ "docstatus": 0,
+ "doctype": "Print Format",
+ "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Receipt Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Received On\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Received From\"), doc.pay_to_recd_from),\n        (_(\"Amount\"), \"<strong>\" + doc.get_formatted(\"total_amount\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-xs-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n",
+ "idx": 1,
+ "modified": "2015-01-12 11:03:22.893209",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Payment Receipt Voucher",
+ "owner": "Administrator",
+ "print_format_type": "Server",
  "standard": "Yes"
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 6836826..8ecbc8d 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -23,12 +23,12 @@
 		cond = "fy.name = %(fiscal_year)s"
 	else:
 		cond = "%(transaction_date)s >= fy.year_start_date and %(transaction_date)s <= fy.year_end_date"
-		
+
 	if company:
 		cond += """ and (not exists(select name from `tabFiscal Year Company` fyc where fyc.parent = fy.name)
 			or exists(select company from `tabFiscal Year Company` fyc where fyc.parent = fy.name and fyc.company=%(company)s ))"""
-		
-	fy = frappe.db.sql("""select fy.name, fy.year_start_date, fy.year_end_date from `tabFiscal Year` fy 
+
+	fy = frappe.db.sql("""select fy.name, fy.year_start_date, fy.year_end_date from `tabFiscal Year` fy
 		where %s order by fy.year_start_date desc""" % cond, {
 			"fiscal_year": fiscal_year,
 			"transaction_date": transaction_date,
@@ -36,7 +36,7 @@
 		})
 
 	if not fy:
-		error_msg = _("""{0} {1} not in any Fiscal Year""").format(label, formatdate(transaction_date))
+		error_msg = _("""{0} {1} not in any Fiscal Year. For more details check {2}.""").format(label, formatdate(transaction_date), "https://erpnext.com/kb/accounts/fiscal-year-error")
 		if verbose==1: frappe.msgprint(error_msg)
 		raise FiscalYearError, error_msg
 	return fy
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js
index 27d7bc8..1651e15 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.js
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.js
@@ -180,7 +180,7 @@
 	calculate_item_values: function() {
 		var me = this;
 
-		$.each(this.frm.item_doclist, function(i, item) {
+		$.each(this.frm.doc["items"], function(i, item) {
 			frappe.model.round_floats_in(item);
 			item.amount = flt(item.rate * item.qty, precision("amount", item));
 			item.item_tax_amount = 0.0;
@@ -196,7 +196,7 @@
 		var me = this;
 
 		this.frm.doc.net_total = this.frm.doc.net_total_import = 0.0;
-		$.each(this.frm.item_doclist, function(i, item) {
+		$.each(this.frm.doc["items"], function(i, item) {
 			me.frm.doc.net_total += item.base_amount;
 			me.frm.doc.net_total_import += item.amount;
 		});
@@ -205,10 +205,11 @@
 	},
 
 	calculate_totals: function() {
-		var tax_count = this.frm.tax_doclist.length;
+		var tax_count = this.frm.doc["taxes"].length;
 		this.frm.doc.grand_total = flt(tax_count ?
-			this.frm.tax_doclist[tax_count - 1].total : this.frm.doc.net_total);
-		this.frm.doc.grand_total_import = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate);
+			this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
+		this.frm.doc.grand_total_import = flt(tax_count ?
+			flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total_import);
 
 		this.frm.doc.total_tax = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
 			precision("total_tax"));
@@ -229,12 +230,12 @@
 		this.frm.doc.other_charges_added = 0.0
 		this.frm.doc.other_charges_deducted = 0.0
 		if(tax_count) {
-			this.frm.doc.other_charges_added = frappe.utils.sum($.map(this.frm.tax_doclist,
+			this.frm.doc.other_charges_added = frappe.utils.sum($.map(this.frm.doc["taxes"],
 				function(tax) { return (tax.add_deduct_tax == "Add"
 					&& in_list(["Valuation and Total", "Total"], tax.category)) ?
 					tax.tax_amount : 0.0; }));
 
-			this.frm.doc.other_charges_deducted = frappe.utils.sum($.map(this.frm.tax_doclist,
+			this.frm.doc.other_charges_deducted = frappe.utils.sum($.map(this.frm.doc["taxes"],
 				function(tax) { return (tax.add_deduct_tax == "Deduct"
 					&& in_list(["Valuation and Total", "Total"], tax.category)) ?
 					tax.tax_amount : 0.0; }));
@@ -252,17 +253,17 @@
 		this._super();
 		this.frm.doc.in_words = this.frm.doc.in_words_import = "";
 
-		if(this.frm.item_doclist.length) {
-			if(!frappe.meta.get_docfield(this.frm.item_doclist[0].doctype, "item_tax_amount", this.frm.doctype)) {
-				$.each(this.frm.item_doclist, function(i, item) {
+		if(this.frm.doc["items"].length) {
+			if(!frappe.meta.get_docfield(this.frm.doc["items"][0].doctype, "item_tax_amount", this.frm.doctype)) {
+				$.each(this.frm.doc["items"], function(i, item) {
 					delete item["item_tax_amount"];
 				});
 			}
 		}
 
-		if(this.frm.tax_doclist.length) {
-			if(!frappe.meta.get_docfield(this.frm.tax_doclist[0].doctype, "tax_amount_after_discount_amount", this.frm.doctype)) {
-				$.each(this.frm.tax_doclist, function(i, tax) {
+		if(this.frm.doc["taxes"].length) {
+			if(!frappe.meta.get_docfield(this.frm.doc["taxes"][0].doctype, "tax_amount_after_discount_amount", this.frm.doctype)) {
+				$.each(this.frm.doc["taxes"], function(i, tax) {
 					delete tax["tax_amount_after_discount_amount"];
 				});
 			}
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 0f24d59..b43af26 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -132,7 +132,7 @@
    "search_index": 1
   }, 
   {
-   "fieldname": "price_list_and_currency", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -775,7 +775,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-01-06 17:41:57.148411", 
+ "modified": "2015-01-15 07:34:27.901777", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
index 90a0594..a938481 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
@@ -132,7 +132,7 @@
    "search_index": 1
   }, 
   {
-   "fieldname": "currency_price_list", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -575,7 +575,7 @@
  "icon": "icon-shopping-cart", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-01-07 10:34:25.299110", 
+ "modified": "2015-01-15 07:34:12.734538", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier Quotation", 
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index cf8a11c..bb5531f 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -291,7 +291,7 @@
 			self.precision("tax_amount", tax))
 
 	def adjust_discount_amount_loss(self, tax):
-		discount_amount_loss = self.grand_total - flt(self.discount_amount) - tax.total
+		discount_amount_loss = self.grand_total - flt(self.base_discount_amount) - tax.total
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, self.precision("tax_amount", tax))
 		tax.total = flt(tax.total + discount_amount_loss, self.precision("total", tax))
@@ -475,7 +475,7 @@
 					max_allowed_amt = flt(ref_amt * (100 + tolerance) / 100)
 
 					if total_billed_amt - max_allowed_amt > 0.01:
-						frappe.throw(_("Cannot overbill for Item {0} in row {0} more than {1}. To allow overbilling, please set in Stock Settings").format(item.item_code, item.idx, max_allowed_amt))
+						frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow overbilling, please set in Stock Settings").format(item.item_code, item.idx, max_allowed_amt))
 
 	def get_company_default(self, fieldname):
 		from erpnext.accounts.utils import get_company_default
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index c3f449c..82da90e 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -115,7 +115,8 @@
 
 	def calculate_totals(self):
 		self.grand_total = flt(self.get("taxes")[-1].total if self.get("taxes") else self.net_total)
-		self.grand_total_import = flt(self.grand_total / self.conversion_rate)
+		self.grand_total_import = flt(self.grand_total / self.conversion_rate) \
+			if self.get("taxes") else self.net_total_import
 
 		self.total_tax = flt(self.grand_total - self.net_total, self.precision("total_tax"))
 
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 937e026..328894c 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -232,16 +232,20 @@
 
 	def apply_discount_amount(self):
 		if self.discount_amount:
+			self.base_discount_amount = flt(self.discount_amount * self.conversion_rate, self.precision("base_discount_amount"))
+
 			grand_total_for_discount_amount = self.get_grand_total_for_discount_amount()
 
 			if grand_total_for_discount_amount:
 				# calculate item amount after Discount Amount
 				for item in self.get("items"):
-					distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount
+					distributed_amount = flt(self.base_discount_amount) * item.base_amount / grand_total_for_discount_amount
 					item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item))
 
 				self.discount_amount_applied = True
 				self._calculate_taxes_and_totals()
+		else:
+			self.base_discount_amount = 0
 
 	def get_grand_total_for_discount_amount(self):
 		actual_taxes_dict = {}
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 4b4be79..5bdd50b 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -167,7 +167,7 @@
 		else:
 			is_expense_account = frappe.db.get_value("Account",
 				item.get("expense_account"), "report_type")=="Profit and Loss"
-			if self.doctype not in ("Purchase Receipt", "Stock Reconciliation") and not is_expense_account:
+			if self.doctype not in ("Purchase Receipt", "Stock Reconciliation", "Stock Entry") and not is_expense_account:
 				frappe.throw(_("Expense / Difference account ({0}) must be a 'Profit or Loss' account")
 					.format(item.get("expense_account")))
 			if is_expense_account and not item.get("cost_center"):
@@ -245,7 +245,7 @@
 	for entry in expected_gle:
 		for e in existing_gle:
 			if entry.account==e.account and entry.against_account==e.against_account \
-				and entry.cost_center==e.cost_center \
+				and (not entry.cost_center or not e.cost_center or entry.cost_center==e.cost_center) \
 				and (entry.debit != e.debit or entry.credit != e.credit):
 					matched = False
 					break
diff --git a/erpnext/hr/doctype/appraisal_template/appraisal_template.json b/erpnext/hr/doctype/appraisal_template/appraisal_template.json
index c814579..6971db1 100644
--- a/erpnext/hr/doctype/appraisal_template/appraisal_template.json
+++ b/erpnext/hr/doctype/appraisal_template/appraisal_template.json
@@ -1,5 +1,6 @@
 {
  "allow_import": 1, 
+ "allow_rename": 1, 
  "autoname": "field:kra_title", 
  "creation": "2012-07-03 13:30:39", 
  "docstatus": 0, 
@@ -46,7 +47,7 @@
  ], 
  "icon": "icon-file-text", 
  "idx": 1, 
- "modified": "2014-12-24 15:01:34.621450", 
+ "modified": "2015-01-15 15:26:55.553233", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Appraisal Template", 
diff --git a/erpnext/hr/doctype/employment_type/employment_type.json b/erpnext/hr/doctype/employment_type/employment_type.json
index bc337f1..8562662 100644
--- a/erpnext/hr/doctype/employment_type/employment_type.json
+++ b/erpnext/hr/doctype/employment_type/employment_type.json
@@ -1,5 +1,6 @@
 {
  "allow_import": 1, 
+ "allow_rename": 1, 
  "autoname": "field:employee_type_name", 
  "creation": "2013-01-10 16:34:14", 
  "docstatus": 0, 
@@ -19,7 +20,7 @@
  ], 
  "icon": "icon-flag", 
  "idx": 1, 
- "modified": "2014-05-27 03:49:10.551828", 
+ "modified": "2015-01-15 15:24:46.680451", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Employment Type", 
diff --git a/erpnext/hr/doctype/holiday_list/holiday_list.json b/erpnext/hr/doctype/holiday_list/holiday_list.json
index a94f8ca..6862c97 100644
--- a/erpnext/hr/doctype/holiday_list/holiday_list.json
+++ b/erpnext/hr/doctype/holiday_list/holiday_list.json
@@ -1,99 +1,99 @@
 {
- "allow_import": 1,
- "autoname": "field:holiday_list_name",
- "creation": "2013-01-10 16:34:14",
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "Master",
+ "allow_import": 1, 
+ "allow_rename": 1, 
+ "autoname": "field:holiday_list_name", 
+ "creation": "2013-01-10 16:34:14", 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Master", 
  "fields": [
   {
-   "fieldname": "holiday_list_name",
-   "fieldtype": "Data",
-   "in_list_view": 1,
-   "label": "Holiday List Name",
-   "oldfieldname": "holiday_list_name",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
-   "reqd": 1,
-   "unique": 0
-  },
-  {
-   "fieldname": "is_default",
-   "fieldtype": "Check",
-   "in_list_view": 1,
-   "label": "Default",
-   "permlevel": 0
-  },
-  {
-   "fieldname": "fiscal_year",
-   "fieldtype": "Link",
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Fiscal Year",
-   "oldfieldname": "fiscal_year",
-   "oldfieldtype": "Link",
-   "options": "Fiscal Year",
-   "permlevel": 0,
+   "fieldname": "holiday_list_name", 
+   "fieldtype": "Data", 
+   "in_list_view": 1, 
+   "label": "Holiday List Name", 
+   "oldfieldname": "holiday_list_name", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
    "reqd": 1
-  },
+  }, 
   {
-   "fieldname": "weekly_off",
-   "fieldtype": "Select",
-   "in_list_view": 1,
-   "label": "Weekly Off",
-   "no_copy": 1,
-   "options": "\nSunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday",
-   "permlevel": 0,
-   "print_hide": 1,
-   "report_hide": 1
-  },
-  {
-   "fieldname": "get_weekly_off_dates",
-   "fieldtype": "Button",
-   "label": "Get Weekly Off Dates",
-   "options": "get_weekly_off_dates",
+   "fieldname": "is_default", 
+   "fieldtype": "Check", 
+   "in_list_view": 1, 
+   "label": "Default", 
    "permlevel": 0
-  },
+  }, 
   {
-   "fieldname": "holidays",
-   "fieldtype": "Table",
-   "label": "Holidays",
-   "oldfieldname": "holiday_list_details",
-   "oldfieldtype": "Table",
-   "options": "Holiday",
-   "permlevel": 0,
+   "fieldname": "fiscal_year", 
+   "fieldtype": "Link", 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Fiscal Year", 
+   "oldfieldname": "fiscal_year", 
+   "oldfieldtype": "Link", 
+   "options": "Fiscal Year", 
+   "permlevel": 0, 
+   "reqd": 1
+  }, 
+  {
+   "fieldname": "weekly_off", 
+   "fieldtype": "Select", 
+   "in_list_view": 1, 
+   "label": "Weekly Off", 
+   "no_copy": 1, 
+   "options": "\nSunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "report_hide": 1
+  }, 
+  {
+   "fieldname": "get_weekly_off_dates", 
+   "fieldtype": "Button", 
+   "label": "Get Weekly Off Dates", 
+   "options": "get_weekly_off_dates", 
+   "permlevel": 0
+  }, 
+  {
+   "fieldname": "holidays", 
+   "fieldtype": "Table", 
+   "label": "Holidays", 
+   "oldfieldname": "holiday_list_details", 
+   "oldfieldtype": "Table", 
+   "options": "Holiday", 
+   "permlevel": 0, 
    "reqd": 0
-  },
+  }, 
   {
-   "fieldname": "clear_table",
-   "fieldtype": "Button",
-   "label": "Clear Table",
-   "options": "clear_table",
+   "fieldname": "clear_table", 
+   "fieldtype": "Button", 
+   "label": "Clear Table", 
+   "options": "clear_table", 
    "permlevel": 0
   }
- ],
- "icon": "icon-calendar",
- "idx": 1,
- "modified": "2014-12-24 15:32:58.469070",
- "modified_by": "Administrator",
- "module": "HR",
- "name": "Holiday List",
- "owner": "Administrator",
+ ], 
+ "icon": "icon-calendar", 
+ "idx": 1, 
+ "modified": "2015-01-15 15:26:20.031592", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "Holiday List", 
+ "owner": "Administrator", 
  "permissions": [
   {
-   "cancel": 0,
-   "create": 1,
-   "delete": 1,
-   "email": 1,
-   "permlevel": 0,
-   "print": 1,
-   "read": 1,
-   "report": 1,
-   "role": "HR Manager",
-   "submit": 0,
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "HR Manager", 
+   "submit": 0, 
    "write": 1
   }
- ],
- "sort_field": "modified",
+ ], 
+ "sort_field": "modified", 
  "sort_order": "DESC"
-}
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index e01f738..2888631 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -33,7 +33,7 @@
 				cur_frm.set_intro(__("You are the Leave Approver for this record. Please Update the 'Status' and Save"));
 				cur_frm.toggle_enable("status", true);
 			} else {
-				cur_frm.set_intro(__("This Leave Application is pending approval. Only the Leave Apporver can update status."))
+				cur_frm.set_intro(__("This Leave Application is pending approval. Only the Leave Approver can update status."))
 				cur_frm.toggle_enable("status", false);
 			}
 		}
diff --git a/erpnext/hr/doctype/leave_type/leave_type.json b/erpnext/hr/doctype/leave_type/leave_type.json
index 9ce967fe..ff19dd2 100644
--- a/erpnext/hr/doctype/leave_type/leave_type.json
+++ b/erpnext/hr/doctype/leave_type/leave_type.json
@@ -1,5 +1,6 @@
 {
  "allow_import": 1, 
+ "allow_rename": 1, 
  "autoname": "field:leave_type_name", 
  "creation": "2013-02-21 09:55:58", 
  "docstatus": 0, 
@@ -62,7 +63,7 @@
  ], 
  "icon": "icon-flag", 
  "idx": 1, 
- "modified": "2014-05-27 03:49:13.297832", 
+ "modified": "2015-01-15 12:37:30.557739", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Leave Type", 
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index afdf10f..636d86b 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -8,6 +8,8 @@
 from frappe import _
 from frappe.model.document import Document
 
+from operator import itemgetter
+
 class BOM(Document):
 
 	def autoname(self):
@@ -335,7 +337,7 @@
 		"Add items to Flat BOM table"
 		frappe.db.sql("""delete from `tabBOM Explosion Item` where parent=%s""", self.name)
 		self.set('exploded_items', [])
-		for d in self.cur_exploded_items:
+		for d in sorted(self.cur_exploded_items, key=itemgetter(0)):
 			ch = self.append('exploded_items', {})
 			for i in self.cur_exploded_items[d].keys():
 				ch.set(i, self.cur_exploded_items[d][i])
diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py
index 58a49c1..92ab915 100644
--- a/erpnext/manufacturing/doctype/production_order/test_production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py
@@ -11,7 +11,7 @@
 from erpnext.projects.doctype.time_log.time_log import OverProductionError
 
 class TestProductionOrder(unittest.TestCase):
-	def test_planned_qty(self):
+	def check_planned_qty(self):
 		set_perpetual_inventory(0)
 
 		planned0 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") or 0
@@ -30,11 +30,15 @@
 		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4))
 		for d in s.get("items"):
 			d.s_warehouse = "Stores - _TC"
+		s.fiscal_year = "_Test Fiscal Year 2013"
+		s.posting_date = "2013-01-02"
 		s.insert()
 		s.submit()
 
 		# from wip to fg
 		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 4))
+		s.fiscal_year = "_Test Fiscal Year 2013"
+		s.posting_date = "2013-01-03"
 		s.insert()
 		s.submit()
 
@@ -47,7 +51,7 @@
 
 	def test_over_production(self):
 		from erpnext.manufacturing.doctype.production_order.production_order import StockOverProductionError
-		pro_doc = self.test_planned_qty()
+		pro_doc = self.check_planned_qty()
 
 		test_stock_entry.make_stock_entry(item_code="_Test Item",
 			target="_Test Warehouse - _TC", qty=100, incoming_rate=100)
@@ -55,6 +59,8 @@
 			target="_Test Warehouse - _TC", qty=100, incoming_rate=100)
 
 		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 7))
+		s.fiscal_year = "_Test Fiscal Year 2013"
+		s.posting_date = "2013-01-04"
 		s.insert()
 
 		self.assertRaises(StockOverProductionError, s.submit)
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js
index b17303d..7a1fe59 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js
@@ -24,6 +24,13 @@
 	}
 }
 
+cur_frm.cscript.raise_purchase_request = function(doc, cdt, cdn) {
+	return frappe.call({
+		method: "raise_purchase_request",
+		doc:doc
+	})
+}
+
 cur_frm.cscript.download_materials_required = function(doc, cdt, cdn) {
 	return $c_obj(doc, 'validate_data', '', function(r, rt) {
 		if (!r['exc'])
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 a69f514..5c2de5b 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
@@ -1,180 +1,180 @@
 {
- "creation": "2013-01-21 12:03:47", 
- "default_print_format": "Standard", 
- "docstatus": 0, 
- "doctype": "DocType", 
+ "creation": "2013-01-21 12:03:47",
+ "default_print_format": "Standard",
+ "docstatus": 0,
+ "doctype": "DocType",
  "fields": [
   {
-   "description": "Select Sales Orders from which you want to create Production Orders.", 
-   "fieldname": "select_sales_orders", 
-   "fieldtype": "Section Break", 
-   "label": "Select Sales Orders", 
+   "description": "Select Sales Orders from which you want to create Production Orders.",
+   "fieldname": "select_sales_orders",
+   "fieldtype": "Section Break",
+   "label": "Select Sales Orders",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "column_break0", 
-   "fieldtype": "Column Break", 
-   "permlevel": 0, 
+   "fieldname": "column_break0",
+   "fieldtype": "Column Break",
+   "permlevel": 0,
    "width": "50%"
-  }, 
+  },
   {
-   "fieldname": "fg_item", 
-   "fieldtype": "Link", 
-   "in_list_view": 1, 
-   "label": "Filter based on item", 
-   "options": "Item", 
+   "fieldname": "fg_item",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Filter based on item",
+   "options": "Item",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "customer", 
-   "fieldtype": "Link", 
-   "in_list_view": 1, 
-   "label": "Filter based on customer", 
-   "options": "Customer", 
+   "fieldname": "customer",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Filter based on customer",
+   "options": "Customer",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "company", 
-   "fieldtype": "Link", 
-   "in_list_view": 1, 
-   "label": "Company", 
-   "options": "Company", 
-   "permlevel": 0, 
+   "fieldname": "company",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Company",
+   "options": "Company",
+   "permlevel": 0,
    "reqd": 1
-  }, 
+  },
   {
-   "fieldname": "column_break1", 
-   "fieldtype": "Column Break", 
-   "permlevel": 0, 
+   "fieldname": "column_break1",
+   "fieldtype": "Column Break",
+   "permlevel": 0,
    "width": "50%"
-  }, 
+  },
   {
-   "fieldname": "from_date", 
-   "fieldtype": "Date", 
-   "label": "From Date", 
+   "fieldname": "from_date",
+   "fieldtype": "Date",
+   "label": "From Date",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "to_date", 
-   "fieldtype": "Date", 
-   "label": "To Date", 
+   "fieldname": "to_date",
+   "fieldtype": "Date",
+   "label": "To Date",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "section_break1", 
-   "fieldtype": "Section Break", 
-   "options": "Simple", 
+   "fieldname": "section_break1",
+   "fieldtype": "Section Break",
+   "options": "Simple",
    "permlevel": 0
-  }, 
+  },
   {
-   "description": "Pull sales orders (pending to deliver) based on the above criteria", 
-   "fieldname": "get_sales_orders", 
-   "fieldtype": "Button", 
-   "label": "Get Sales Orders", 
-   "options": "get_open_sales_orders", 
+   "description": "Pull sales orders (pending to deliver) based on the above criteria",
+   "fieldname": "get_sales_orders",
+   "fieldtype": "Button",
+   "label": "Get Sales Orders",
+   "options": "get_open_sales_orders",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "sales_orders", 
-   "fieldtype": "Table", 
-   "label": "Sales Orders", 
-   "options": "Production Plan Sales Order", 
+   "fieldname": "sales_orders",
+   "fieldtype": "Table",
+   "label": "Sales Orders",
+   "options": "Production Plan Sales Order",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "items_for_production", 
-   "fieldtype": "Section Break", 
-   "label": "Select Items", 
+   "fieldname": "items_for_production",
+   "fieldtype": "Section Break",
+   "label": "Select Items",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "get_items_from_so", 
-   "fieldtype": "Button", 
-   "label": "Get Items From Sales Orders", 
-   "options": "get_items_from_so", 
+   "fieldname": "get_items_from_so",
+   "fieldtype": "Button",
+   "label": "Get Items From Sales Orders",
+   "options": "get_items_from_so",
    "permlevel": 0
-  }, 
+  },
   {
-   "default": "1", 
-   "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
-   "fieldname": "use_multi_level_bom", 
-   "fieldtype": "Check", 
-   "label": "Use Multi-Level BOM", 
-   "permlevel": 0, 
+   "default": "1",
+   "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.",
+   "fieldname": "use_multi_level_bom",
+   "fieldtype": "Check",
+   "label": "Use Multi-Level BOM",
+   "permlevel": 0,
    "reqd": 0
-  }, 
+  },
   {
-   "fieldname": "items", 
-   "fieldtype": "Table", 
-   "label": "Items", 
-   "options": "Production Plan Item", 
+   "fieldname": "items",
+   "fieldtype": "Table",
+   "label": "Items",
+   "options": "Production Plan Item",
    "permlevel": 0
-  }, 
+  },
   {
-   "description": "Enter items and planned qty for which you want to raise production orders or download raw materials for analysis.", 
-   "fieldname": "create_production_orders", 
-   "fieldtype": "Section Break", 
-   "label": "Production Orders", 
+   "description": "Enter items and planned qty for which you want to raise production orders or download raw materials for analysis.",
+   "fieldname": "create_production_orders",
+   "fieldtype": "Section Break",
+   "label": "Production Orders",
    "permlevel": 0
-  }, 
+  },
   {
-   "description": "Separate production order will be created for each finished good item.", 
-   "fieldname": "raise_production_order", 
-   "fieldtype": "Button", 
-   "label": "Create Production Orders", 
-   "options": "raise_production_order", 
+   "description": "Separate production order will be created for each finished good item.",
+   "fieldname": "raise_production_order",
+   "fieldtype": "Button",
+   "label": "Create Production Orders",
+   "options": "raise_production_order",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "sb5", 
-   "fieldtype": "Section Break", 
-   "label": "Material Requirement", 
+   "fieldname": "sb5",
+   "fieldtype": "Section Break",
+   "label": "Material Requirement",
    "permlevel": 0
-  }, 
+  },
   {
-   "fieldname": "purchase_request_for_warehouse", 
-   "fieldtype": "Link", 
-   "label": "Material Request For Warehouse", 
-   "options": "Warehouse", 
+   "fieldname": "purchase_request_for_warehouse",
+   "fieldtype": "Link",
+   "label": "Material Request For Warehouse",
+   "options": "Warehouse",
    "permlevel": 0
-  }, 
+  },
   {
-   "description": "Items to be requested which are \"Out of Stock\" considering all warehouses based on projected qty and minimum order qty", 
-   "fieldname": "raise_purchase_request", 
-   "fieldtype": "Button", 
-   "label": "Create Material Requests", 
-   "options": "raise_purchase_request", 
+   "description": "Items to be requested which are \"Out of Stock\" considering all warehouses based on projected qty and minimum order qty",
+   "fieldname": "raise_purchase_request",
+   "fieldtype": "Button",
+   "label": "Create Material Requests",
+   "options": "",
    "permlevel": 0
-  }, 
+  },
   {
-   "description": "Download a report containing all raw materials with their latest inventory status", 
-   "fieldname": "download_materials_required", 
-   "fieldtype": "Button", 
-   "label": "Download Materials Required", 
+   "description": "Download a report containing all raw materials with their latest inventory status",
+   "fieldname": "download_materials_required",
+   "fieldtype": "Button",
+   "label": "Download Materials Required",
    "permlevel": 0
   }
- ], 
- "icon": "icon-calendar", 
- "idx": 1, 
- "in_create": 1, 
- "issingle": 1, 
- "modified": "2014-12-24 16:36:06.267344", 
- "modified_by": "Administrator", 
- "module": "Manufacturing", 
- "name": "Production Planning Tool", 
- "owner": "jai@webnotestech.com", 
+ ],
+ "icon": "icon-calendar",
+ "idx": 1,
+ "in_create": 1,
+ "issingle": 1,
+ "modified": "2015-01-11 21:53:21.253556",
+ "modified_by": "Administrator",
+ "module": "Manufacturing",
+ "name": "Production Planning Tool",
+ "owner": "jai@webnotestech.com",
  "permissions": [
   {
-   "create": 1, 
-   "email": 1, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 0, 
-   "role": "Manufacturing User", 
-   "submit": 0, 
+   "create": 1,
+   "email": 1,
+   "permlevel": 0,
+   "print": 1,
+   "read": 1,
+   "report": 0,
+   "role": "Manufacturing User",
+   "submit": 0,
    "write": 1
   }
- ], 
+ ],
  "read_only": 1
-}
\ No newline at end of file
+}
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index c9001df..9721646 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -87,6 +87,7 @@
 erpnext.patches.v4_2.update_requested_and_ordered_qty
 erpnext.patches.v4_4.make_email_accounts
 execute:frappe.delete_doc("DocType", "Contact Control")
+erpnext.patches.v4_2.discount_amount
 erpnext.patches.v4_2.reset_bom_costs
 erpnext.patches.v5_0.update_frozen_accounts_permission_role
 erpnext.patches.v5_0.update_dn_against_doc_fields
@@ -102,3 +103,4 @@
 erpnext.patches.v4_1.fix_jv_remarks
 erpnext.patches.v5_0.recalculate_total_amount_in_jv
 erpnext.patches.v5_0.remove_shopping_cart_app
+erpnext.patches.v5_0.update_companywise_payment_account
diff --git a/erpnext/patches/v4_2/discount_amount.py b/erpnext/patches/v4_2/discount_amount.py
new file mode 100644
index 0000000..3ce10ca
--- /dev/null
+++ b/erpnext/patches/v4_2/discount_amount.py
@@ -0,0 +1,12 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.modules import scrub, get_doctype_module
+
+def execute():
+	for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
+		frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
+		frappe.db.sql("""update `tab{0}` set base_discount_amount=discount_amount,
+			discount_amount=discount_amount/conversion_rate""".format(dt))
diff --git a/erpnext/patches/v5_0/update_companywise_payment_account.py b/erpnext/patches/v5_0/update_companywise_payment_account.py
new file mode 100644
index 0000000..71d7552
--- /dev/null
+++ b/erpnext/patches/v5_0/update_companywise_payment_account.py
@@ -0,0 +1,20 @@
+
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+
+def execute():
+	frappe.reload_doc('accounts', 'doctype', 'mode_of_payment')
+
+	mode_of_payment_list = frappe.db.sql("""select name, default_account
+		from `tabMode of Payment`""", as_dict=1)
+
+	for d in mode_of_payment_list:
+		if d.get("default_account"):
+			parent_doc = frappe.get_doc("Mode of Payment", d.get("name"))
+
+			parent_doc.set("mode_of_payment_details",
+				[{"company": frappe.db.get_value("Account", d.get("default_account"), "company"),
+				"default_account": d.get("default_account")}])
+			parent_doc.save()
diff --git a/erpnext/projects/doctype/activity_type/activity_type.json b/erpnext/projects/doctype/activity_type/activity_type.json
index e4a6bc1..73b22e1 100644
--- a/erpnext/projects/doctype/activity_type/activity_type.json
+++ b/erpnext/projects/doctype/activity_type/activity_type.json
@@ -1,5 +1,6 @@
 {
  "allow_import": 1, 
+ "allow_rename": 1, 
  "autoname": "field:activity_type", 
  "creation": "2013-03-05 10:14:59", 
  "docstatus": 0, 
@@ -18,7 +19,7 @@
  "icon": "icon-flag", 
  "idx": 1, 
  "in_dialog": 0, 
- "modified": "2015-01-07 15:12:20.500625", 
+ "modified": "2015-01-15 15:22:10.640553", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Activity Type", 
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index 107114e..e5fef9c 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -55,11 +55,18 @@
 	refresh: function() {
 		erpnext.toggle_naming_series();
 		erpnext.hide_company();
+		this.hide_currency_and_price_list()
 		this.show_item_wise_taxes();
 		this.set_dynamic_labels();
-
 		erpnext.pos.make_pos_btn(this.frm);
+	},
 
+	hide_currency_and_price_list: function() {
+		if(this.frm.doc.docstatus > 0) {
+			hide_field("currency_and_price_list");
+		} else {
+			unhide_field("currency_and_price_list");
+		}
 	},
 
 	item_code: function(doc, cdt, cdn) {
@@ -356,7 +363,7 @@
 		if (item) {
 			append_item(item);
 		} else {
-			$.each(this.get_item_doclist(), function(i, d) {
+			$.each(this.frm.doc["items"], function(i, d) {
 				append_item(d);
 			});
 		}
@@ -426,8 +433,6 @@
 	},
 
 	validate_inclusive_tax: function(tax) {
-		if(!this.frm.tax_doclist) this.frm.tax_doclist = this.get_tax_doclist();
-
 		var actual_type_error = function() {
 			var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
 			frappe.throw(msg);
@@ -444,11 +449,11 @@
 				// inclusive tax cannot be of type Actual
 				actual_type_error();
 			} else if(tax.charge_type == "On Previous Row Amount" &&
-				!cint(this.frm.tax_doclist[tax.row_id - 1].included_in_print_rate)) {
+				!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)) {
 					// referred row should also be an inclusive tax
 					on_previous_row_error(tax.row_id);
 			} else if(tax.charge_type == "On Previous Row Total") {
-				var taxes_not_included = $.map(this.frm.tax_doclist.slice(0, tax.row_id),
+				var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
 					function(t) { return cint(t.included_in_print_rate) ? null : t; });
 				if(taxes_not_included.length > 0) {
 					// all rows above this tax should be inclusive
@@ -473,7 +478,7 @@
 		var tax_accounts = [];
 		var company_currency = this.get_company_currency();
 
-		$.each(this.get_tax_doclist(), function(i, tax) {
+		$.each(this.frm.doc["taxes"], function(i, tax) {
 			var tax_amount_precision = precision("tax_amount", tax);
 			var tax_rate_precision = precision("rate", tax);
 			$.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
@@ -502,7 +507,7 @@
 
 		var distinct_item_names = [];
 		var distinct_items = [];
-		$.each(this.get_item_doclist(), function(i, item) {
+		$.each(this.frm.doc["items"], function(i, item) {
 			if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) {
 				distinct_item_names.push(item.item_code || item.item_name);
 				distinct_items.push(item);
@@ -547,14 +552,6 @@
 		return valid;
 	},
 
-	get_item_doclist: function() {
-		return this.frm.doc["items"] || [];
-	},
-
-	get_tax_doclist: function() {
-		return this.frm.doc["taxes"] || [];
-	},
-
 	validate_conversion_rate: function() {
 		this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
 		var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
@@ -582,9 +579,6 @@
 
 	_calculate_taxes_and_totals: function() {
 		this.validate_conversion_rate();
-		this.frm.item_doclist = this.get_item_doclist();
-		this.frm.tax_doclist = this.get_tax_doclist();
-
 		this.calculate_item_values();
 		this.initialize_taxes();
 		this.determine_exclusive_rate && this.determine_exclusive_rate();
@@ -592,14 +586,13 @@
 		this.calculate_taxes();
 		this.calculate_totals();
 		this._cleanup();
-
 		this.show_item_wise_taxes();
 	},
 
 	initialize_taxes: function() {
 		var me = this;
 
-		$.each(this.frm.tax_doclist, function(i, tax) {
+		$.each(this.frm.doc["taxes"], function(i, tax) {
 			tax.item_wise_tax_detail = {};
 			tax_fields = ["total", "tax_amount_after_discount_amount",
 				"tax_amount_for_current_item", "grand_total_for_current_item",
@@ -621,23 +614,23 @@
 		var actual_tax_dict = {};
 
 		// maintain actual tax rate based on idx
-		$.each(this.frm.tax_doclist, function(i, tax) {
+		$.each(this.frm.doc["taxes"], function(i, tax) {
 			if (tax.charge_type == "Actual") {
 				actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
 			}
 		});
 
-		$.each(this.frm.item_doclist, function(n, item) {
+		$.each(this.frm.doc["items"], function(n, item) {
 			var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
 
-			$.each(me.frm.tax_doclist, function(i, tax) {
+			$.each(me.frm.doc["taxes"], function(i, tax) {
 				// tax_amount represents the amount of tax for the current step
 				var current_tax_amount = me.get_current_tax_amount(item, tax, item_tax_map);
 
 				// Adjust divisional loss to the last item
 				if (tax.charge_type == "Actual") {
 					actual_tax_dict[tax.idx] -= current_tax_amount;
-					if (n == me.frm.item_doclist.length - 1) {
+					if (n == me.frm.doc["items"].length - 1) {
 						current_tax_amount += actual_tax_dict[tax.idx]
 					}
 				}
@@ -669,7 +662,7 @@
 						precision("total", tax));
 				} else {
 					tax.grand_total_for_current_item =
-						flt(me.frm.tax_doclist[i-1].grand_total_for_current_item + current_tax_amount,
+						flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount,
 							precision("total", tax));
 				}
 
@@ -677,11 +670,11 @@
 				tax.total += tax.grand_total_for_current_item;
 
 				// set precision in the last item iteration
-				if (n == me.frm.item_doclist.length - 1) {
+				if (n == me.frm.doc["items"].length - 1) {
 					me.round_off_totals(tax);
 
 					// adjust Discount Amount loss in last tax iteration
-					if ((i == me.frm.tax_doclist.length - 1) && me.discount_amount_applied)
+					if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied)
 						me.adjust_discount_amount_loss(tax);
 				}
 			});
@@ -696,7 +689,7 @@
 	},
 
 	adjust_discount_amount_loss: function(tax) {
-		var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
+		var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, precision("tax_amount", tax));
 		tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
@@ -710,19 +703,18 @@
 			// distribute the tax amount proportionally to each item row
 			var actual = flt(tax.rate, precision("tax_amount", tax));
 			current_tax_amount = this.frm.doc.net_total ?
-				((item.base_amount / this.frm.doc.net_total) * actual) :
-				0.0;
+			((item.base_amount / this.frm.doc.net_total) * actual) : 0.0;
 
 		} else if(tax.charge_type == "On Net Total") {
 			current_tax_amount = (tax_rate / 100.0) * item.base_amount;
 
 		} else if(tax.charge_type == "On Previous Row Amount") {
 			current_tax_amount = (tax_rate / 100.0) *
-				this.frm.tax_doclist[cint(tax.row_id) - 1].tax_amount_for_current_item;
+				this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item;
 
 		} else if(tax.charge_type == "On Previous Row Total") {
 			current_tax_amount = (tax_rate / 100.0) *
-				this.frm.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item;
+				this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
 		}
 
 		current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax));
@@ -734,7 +726,7 @@
 	},
 
 	_cleanup: function() {
-		$.each(this.frm.tax_doclist, function(i, tax) {
+		$.each(this.frm.doc["taxes"], function(i, tax) {
 			$.each(["tax_amount_for_current_item", "grand_total_for_current_item",
 				"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"],
 				function(i, fieldname) { delete tax[fieldname]; });
diff --git a/erpnext/selling/doctype/opportunity/opportunity.py b/erpnext/selling/doctype/opportunity/opportunity.py
index af170c4..001ba3b 100644
--- a/erpnext/selling/doctype/opportunity/opportunity.py
+++ b/erpnext/selling/doctype/opportunity/opportunity.py
@@ -93,6 +93,9 @@
 				(not cint(self.get("__islocal"))) else None,
 		})
 
+		if not self.enquiry_from:
+			frappe.throw(_("Opportunity From field is mandatory"))
+
 		self.set_status()
 		self.validate_item_details()
 		self.validate_uom_is_integer("uom", "qty")
diff --git a/erpnext/selling/doctype/opportunity/test_records.json b/erpnext/selling/doctype/opportunity/test_records.json
index dcda5d5..044d230 100644
--- a/erpnext/selling/doctype/opportunity/test_records.json
+++ b/erpnext/selling/doctype/opportunity/test_records.json
@@ -5,6 +5,8 @@
 		"enquiry_from": "Lead",
 		"enquiry_type": "Sales",
 		"lead": "_T-Lead-00001",
+		"transaction_date": "2013-12-12",
+		"fiscal_year": "_Test Fiscal Year 2013",
 		"items": [{
 			"item_name": "Test Item",
 			"description": "Some description"
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 0f856d7..38cce98 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -197,7 +197,7 @@
    "search_index": 0
   }, 
   {
-   "fieldname": "section_break0", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -406,6 +406,15 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "other_charges_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Taxes and Charges Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Taxes and Charges Total (Company Currency)", 
@@ -422,22 +431,23 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "other_charges_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Taxes and Charges Total", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "label": "Totals", 
@@ -800,7 +810,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "max_attachments": 1, 
- "modified": "2015-01-06 17:17:04.598365", 
+ "modified": "2015-01-15 07:33:06.919752", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Quotation", 
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index 6a7e00e..e834e00 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -219,7 +219,7 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "sec_break45", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -326,19 +326,6 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "column_break_33", 
-   "fieldtype": "Column Break", 
-   "permlevel": 0
-  }, 
-  {
-   "fieldname": "net_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Net Total", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "net_total", 
    "fieldtype": "Currency", 
    "label": "Net Total (Company Currency)", 
@@ -352,6 +339,19 @@
    "width": "150px"
   }, 
   {
+   "fieldname": "column_break_33", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0
+  }, 
+  {
+   "fieldname": "net_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Net Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "taxes_section", 
    "fieldtype": "Section Break", 
    "label": "Taxes and Charges", 
@@ -421,11 +421,6 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "column_break_46", 
-   "fieldtype": "Column Break", 
-   "permlevel": 0
-  }, 
-  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Taxes and Charges Total (Company Currency)", 
@@ -438,11 +433,27 @@
    "width": "150px"
   }, 
   {
+   "fieldname": "column_break_46", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0
+  }, 
+  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 0
+  }, 
+  {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
    "options": "Company:company:default_currency", 
-   "permlevel": 0
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
   }, 
   {
    "fieldname": "totals", 
@@ -491,14 +502,6 @@
    "width": "200px"
   }, 
   {
-   "fieldname": "advance_paid", 
-   "fieldtype": "Currency", 
-   "label": "Advance Paid", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "oldfieldtype": "Column Break", 
@@ -544,6 +547,15 @@
    "width": "200px"
   }, 
   {
+   "fieldname": "advance_paid", 
+   "fieldtype": "Currency", 
+   "label": "Advance Paid", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "view_details", 
    "fieldtype": "Fold", 
    "label": "View Details", 
@@ -1022,7 +1034,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "issingle": 0, 
- "modified": "2015-01-06 17:28:44.639230", 
+ "modified": "2015-01-15 07:51:42.642249", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Order", 
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 4d76158..48c378f 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -248,7 +248,7 @@
 		var me = this;
 
 		if (!this.discount_amount_applied) {
-			$.each(this.frm.item_doclist, function(i, item) {
+			$.each(this.frm.doc["items"], function(i, item) {
 				frappe.model.round_floats_in(item);
 				item.amount = flt(item.rate * item.qty, precision("amount", item));
 
@@ -261,18 +261,18 @@
 
 	determine_exclusive_rate: function() {
 		var me = this;
-		$.each(me.frm.item_doclist, function(n, item) {
+		$.each(me.frm.doc["items"], function(n, item) {
 			var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
 			var cumulated_tax_fraction = 0.0;
 
-			$.each(me.frm.tax_doclist, function(i, tax) {
+			$.each(me.frm.doc["taxes"], function(i, tax) {
 				tax.tax_fraction_for_current_item = me.get_current_tax_fraction(tax, item_tax_map);
 
 				if(i==0) {
 					tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item;
 				} else {
 					tax.grand_total_fraction_for_current_item =
-						me.frm.tax_doclist[i-1].grand_total_fraction_for_current_item +
+						me.frm.doc["taxes"][i-1].grand_total_fraction_for_current_item +
 						tax.tax_fraction_for_current_item;
 				}
 
@@ -310,11 +310,11 @@
 
 			} else if(tax.charge_type == "On Previous Row Amount") {
 				current_tax_fraction = (tax_rate / 100.0) *
-					this.frm.tax_doclist[cint(tax.row_id) - 1].tax_fraction_for_current_item;
+					this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_fraction_for_current_item;
 
 			} else if(tax.charge_type == "On Previous Row Total") {
 				current_tax_fraction = (tax_rate / 100.0) *
-					this.frm.tax_doclist[cint(tax.row_id) - 1].grand_total_fraction_for_current_item;
+					this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_fraction_for_current_item;
 			}
 		}
 
@@ -325,7 +325,7 @@
 		var me = this;
 		this.frm.doc.net_total = this.frm.doc.net_total_export = 0.0;
 
-		$.each(this.frm.item_doclist, function(i, item) {
+		$.each(this.frm.doc["items"], function(i, item) {
 			me.frm.doc.net_total += item.base_amount;
 			me.frm.doc.net_total_export += item.amount;
 		});
@@ -335,9 +335,9 @@
 
 	calculate_totals: function() {
 		var me = this;
-		var tax_count = this.frm.tax_doclist.length;
+		var tax_count = this.frm.doc["taxes"].length;
 
-		this.frm.doc.grand_total = flt(tax_count ? this.frm.tax_doclist[tax_count - 1].total : this.frm.doc.net_total);
+		this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
 		this.frm.doc.grand_total_export = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate);
 
 		this.frm.doc.other_charges_total = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
@@ -358,17 +358,22 @@
 		var distributed_amount = 0.0;
 
 		if (this.frm.doc.discount_amount) {
+			this.frm.set_value("base_discount_amount",
+				flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_discount_amount")))
+
 			var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
 			// calculate item amount after Discount Amount
 			if (grand_total_for_discount_amount) {
-				$.each(this.frm.item_doclist, function(i, item) {
-					distributed_amount = flt(me.frm.doc.discount_amount) * item.base_amount / grand_total_for_discount_amount;
+				$.each(this.frm.doc["items"], function(i, item) {
+					distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount;
 					item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item));
 				});
 
 				this.discount_amount_applied = true;
 				this._calculate_taxes_and_totals();
 			}
+		} else {
+			this.frm.set_value("base_discount_amount", 0);
 		}
 	},
 
@@ -377,7 +382,7 @@
 		var total_actual_tax = 0.0;
 		var actual_taxes_dict = {};
 
-		$.each(this.frm.tax_doclist, function(i, tax) {
+		$.each(this.frm.doc["taxes"], function(i, tax) {
 			if (tax.charge_type == "Actual")
 				actual_taxes_dict[tax.idx] = tax.tax_amount;
 			else if (actual_taxes_dict[tax.row_id] !== null) {
@@ -504,12 +509,12 @@
 				}
 			});
 		};
-		setup_field_label_map(["net_total", "other_charges_total", "grand_total",
+		setup_field_label_map(["net_total", "other_charges_total", "base_discount_amount", "grand_total",
 			"rounded_total", "in_words",
 			"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"],
 			company_currency);
 
-		setup_field_label_map(["net_total_export", "other_charges_total_export", "grand_total_export",
+		setup_field_label_map(["net_total_export", "other_charges_total_export", "discount_amount", "grand_total_export",
 			"rounded_total_export", "in_words_export"], this.frm.doc.currency);
 
 		cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
@@ -522,7 +527,7 @@
 
 		// toggle fields
 		this.frm.toggle_display(["conversion_rate", "net_total", "other_charges_total",
-			"grand_total", "rounded_total", "in_words"],
+			"grand_total", "rounded_total", "in_words", "base_discount_amount"],
 			this.frm.doc.currency != company_currency);
 
 		this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
diff --git a/erpnext/setup/doctype/print_heading/print_heading.json b/erpnext/setup/doctype/print_heading/print_heading.json
index c788d9e..4d16a24 100644
--- a/erpnext/setup/doctype/print_heading/print_heading.json
+++ b/erpnext/setup/doctype/print_heading/print_heading.json
@@ -1,5 +1,6 @@
 {
  "allow_import": 1, 
+ "allow_rename": 1, 
  "autoname": "field:print_heading", 
  "creation": "2013-01-10 16:34:24", 
  "docstatus": 0, 
@@ -31,7 +32,7 @@
  ], 
  "icon": "icon-font", 
  "idx": 1, 
- "modified": "2014-09-09 05:35:39.239327", 
+ "modified": "2015-01-15 15:25:32.907590", 
  "modified_by": "Administrator", 
  "module": "Setup", 
  "name": "Print Heading", 
diff --git a/erpnext/setup/page/setup_wizard/sample_blog_post.html b/erpnext/setup/page/setup_wizard/data/sample_blog_post.html
similarity index 100%
rename from erpnext/setup/page/setup_wizard/sample_blog_post.html
rename to erpnext/setup/page/setup_wizard/data/sample_blog_post.html
diff --git a/erpnext/setup/page/setup_wizard/sample_home_page.css b/erpnext/setup/page/setup_wizard/data/sample_home_page.css
similarity index 100%
rename from erpnext/setup/page/setup_wizard/sample_home_page.css
rename to erpnext/setup/page/setup_wizard/data/sample_home_page.css
diff --git a/erpnext/setup/page/setup_wizard/sample_home_page.html b/erpnext/setup/page/setup_wizard/data/sample_home_page.html
similarity index 100%
rename from erpnext/setup/page/setup_wizard/sample_home_page.html
rename to erpnext/setup/page/setup_wizard/data/sample_home_page.html
diff --git a/erpnext/setup/page/setup_wizard/default_website.py b/erpnext/setup/page/setup_wizard/default_website.py
index 9bbdab0..5dbb7fc 100644
--- a/erpnext/setup/page/setup_wizard/default_website.py
+++ b/erpnext/setup/page/setup_wizard/default_website.py
@@ -28,8 +28,8 @@
 				'<p>'+_("This is an example website auto-generated from ERPNext")+"</p>"+\
 				'<p><a class="btn btn-primary" href="/login">Login</a></p>',
 			"description": self.company + ":" + (self.tagline or ""),
-			"css": frappe.get_template("setup/page/setup_wizard/sample_home_page.css").render(),
-			"main_section": frappe.get_template("setup/page/setup_wizard/sample_home_page.html").render({
+			"css": frappe.get_template("setup/page/setup_wizard/data/sample_home_page.css").render(),
+			"main_section": frappe.get_template("setup/page/setup_wizard/data/sample_home_page.html").render({
 				"company": self.company, "tagline": (self.tagline or "")
 			})
 		}).insert()
@@ -88,7 +88,7 @@
 			"blogger": blogger.name,
 			"blog_category": blog_category.name,
 			"blog_intro": "My First Blog",
-			"content": frappe.get_template("setup/page/setup_wizard/sample_blog_post.html").render(),
+			"content": frappe.get_template("setup/page/setup_wizard/data/sample_blog_post.html").render(),
 		}).insert()
 
 def test():
diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.css b/erpnext/setup/page/setup_wizard/setup_wizard.css
index 46f9936..6ff5b12 100644
--- a/erpnext/setup/page/setup_wizard/setup_wizard.css
+++ b/erpnext/setup/page/setup_wizard/setup_wizard.css
@@ -3,7 +3,7 @@
 	top: 0px; bottom: 0px;
 	left: 0px; right: 0px;
 	overflow: auto;
-	padding-top: 60px;
+	padding-top: 30px;
 }
 .setup-wizard-wrapper {
 	margin: 0px auto;
@@ -15,13 +15,12 @@
 	}
 }
 
-#page-setup-wizard .panel {
-	background-color: #fff;
-}
-
-#page-setup-wizard .panel-body {
-}
-
 #page-setup-wizard .col-md-6 .control-input .btn {
 	width: 100%;
 }
+
+#page-setup-wizard .form-section {
+	margin: 0px -15px;
+	padding: 0px;
+	max-width: 400px;
+}
diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.js b/erpnext/setup/page/setup_wizard/setup_wizard.js
index 6b847e0..9a557c2 100644
--- a/erpnext/setup/page/setup_wizard/setup_wizard.js
+++ b/erpnext/setup/page/setup_wizard/setup_wizard.js
@@ -38,11 +38,6 @@
 			})
 		},
 		title: __("Welcome"),
-		welcome_html: '<h1 class="text-muted text-center"><i class="icon-magic"></i></h1>\
-			<h2 class="text-center">'+__('ERPNext Setup')+'</h2>\
-			<p class="text-center" style="margin: 0px 100px">' +
-			__('Welcome to ERPNext. Over the next few minutes we will help you setup your ERPNext account. Try and fill in as much information as you have even if it takes a bit longer. It will save you a lot of time later. Good Luck!') +
-			'</p>',
 		working_html: function() { return '<h3 class="text-muted text-center"><i class="icon-refresh icon-spin"></i></h3>\
 			<h2 class="text-center">'+__('Setting up...')+'</h2>\
 			<p class="text-center">' +
@@ -64,22 +59,23 @@
 						reqd:1
 					},
 				],
-				help: __("Welcome to ERPNext. Please select your language to begin the Setup Wizard."),
+				help: "",
 				onload: function(slide) {
 					var me = this;
+					var select = slide.get_field("language");
 
 					if (!this.language_list) {
 						frappe.call({
 							method: "erpnext.setup.page.setup_wizard.setup_wizard.load_languages",
 							callback: function(r) {
 								me.language_list = r.message;
-								slide.get_input("language")
-									.add_options(r.message)
-									.val("english");
+								select.df.options = me.language_list;
+								select.set_input("english");
 							}
 						})
 					} else {
-						slide.get_input("language").add_options(this.language_list);
+						select.df.options = this.language_list;
+						select.refresh();
 					}
 
 					slide.get_input("language").on("change", function() {
@@ -95,7 +91,10 @@
 								$.each(slide.wiz.slide_dict, function(key, s) {
 									s.make();
 								});
-								slide.get_input("language").val(lang);
+
+								// select is re-made after language change
+								var select = slide.get_field("language");
+								select.set_input(lang);
 							}
 						})
 					});
@@ -177,11 +176,13 @@
 						if(country){
 							var timezone_list = frappe.country_info[country].timezones || [];
 							$timezone.add_options(timezone_list.sort());
-							slide.get_input("currency").val(frappe.country_info[country].currency);
+							slide.get_field("currency").set_input(frappe.country_info[country].currency);
 						}
 						// add all timezones at the end, so that user has the option to change it to any timezone
 						$timezone.add_options([""].concat(frappe.all_timezones));
 
+						slide.get_field("timezone").set_input($timezone.val());
+
 						// temporarily set date format
 						frappe.boot.sysdefaults.date_format = (frappe.country_info[country].date_format
 							|| "dd-mm-yyyy");
@@ -221,13 +222,13 @@
 					slide.get_input("company_name").on("change", function() {
 						var parts = slide.get_input("company_name").val().split(" ");
 						var abbr = $.map(parts, function(p) { return p ? p.substr(0,1) : null }).join("");
-						slide.get_input("company_abbr").val(abbr.slice(0, 5).toUpperCase());
+						slide.get_field("company_abbr").set_input(abbr.slice(0, 5).toUpperCase());
 					}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
 
 					slide.get_input("company_abbr").on("change", function() {
 						if(slide.get_input("company_abbr").val().length > 5) {
 							msgprint("Company Abbreviation cannot have more than 5 characters");
-							slide.get_input("company_abbr").val("");
+							slide.get_field("company_abbr").set_input("");
 						}
 					});
 
@@ -235,7 +236,7 @@
 						var year_end_date =
 							frappe.datetime.add_days(frappe.datetime.add_months(
 								frappe.datetime.user_to_obj(slide.get_input("fy_start_date").val()), 12), -1);
-						slide.get_input("fy_end_date").val(frappe.datetime.obj_to_user(year_end_date));
+						slide.get_field("fy_end_date").set_input(frappe.datetime.obj_to_user(year_end_date));
 
 					});
 				}
@@ -366,7 +367,6 @@
 		this.make();
 		this.slides = this.slides;
 		this.slide_dict = {};
-		//this.show_welcome();
 		this.welcomed = true;
 		frappe.set_route(this.page_name, "0");
 	},
@@ -379,22 +379,6 @@
 			<div class="panel-body" style="padding: 40px;">%(html)s</div>\
 		</div>', {html:html}))
 	},
-	show_welcome: function() {
-		if(this.$welcome)
-			return;
-		var me = this;
-		this.$welcome = this.get_message(this.welcome_html +
-			'<br><p class="text-center"><button class="btn btn-primary">'+__("Start")+'</button></p>')
-			.appendTo(this.parent);
-
-		this.$welcome.find(".btn").click(function() {
-			me.$welcome.toggle(false);
-			me.welcomed = true;
-			frappe.set_route(me.page_name, "0");
-		})
-
-		this.current_slide = {"$wrapper": this.$welcome};
-	},
 	show_working: function() {
 		this.hide_current_slide();
 		frappe.set_route(this.page_name);
@@ -452,33 +436,8 @@
 			this.before_load(this);
 		}
 
-		this.$body = $(repl('<div class="panel panel-default">\
-			<div class="panel-heading">\
-				<div class="panel-title row">\
-					<div class="col-sm-12"><h3 style="margin: 0px;">\
-						<i class="%(icon)s text-muted"></i> %(title)s</h3></div>\
-				</div>\
-			</div>\
-			<div class="panel-body">\
-				<div class="progress">\
-					<div class="progress-bar" style="width: %(width)s%"></div>\
-				</div>\
-				<div class="row">\
-					<div class="col-sm-12">\
-						<p>%(help)s</p><br>\
-						<div class="form"></div>\
-					</div>\
-				</div>\
-				<hr>\
-				<div class="footer">\
-					<div class="text-right"><a class="prev-btn hide btn btn-default">'+__('Previous')+'</a> \
-						<a class="next-btn hide btn btn-primary">'+__("Next")+'</a> \
-						<a class="complete-btn hide btn btn-primary"><b>'+__("Complete Setup")+'</b></a>\
-					</div>\
-				</div>\
-			</div>\
-		</div>', {help: __(this.help), title:__(this.title), main_title:__(this.wiz.title), step: this.id + 1,
-				width: (flt(this.id + 1) / (this.wiz.slides.length+1)) * 100, icon:this.icon}))
+		this.$body = $(frappe.render_template("setup_wizard_page",
+			{help: __(this.help), title:__(this.title), main_title:__(this.wiz.title), step: this.id + 1 }))
 			.appendTo(this.$wrapper);
 
 		this.body = this.$body.find(".form")[0];
@@ -530,5 +489,8 @@
 	},
 	get_input: function(fn) {
 		return this.form.get_input(fn);
+	},
+	get_field: function(fn) {
+		return this.form.get_field(fn);
 	}
 })
diff --git a/erpnext/setup/page/setup_wizard/setup_wizard_page.html b/erpnext/setup/page/setup_wizard/setup_wizard_page.html
new file mode 100644
index 0000000..81a79a0
--- /dev/null
+++ b/erpnext/setup/page/setup_wizard/setup_wizard_page.html
@@ -0,0 +1,19 @@
+<div>
+    <h3>{%= title %}</h3>
+    <hr>
+	<div class="row">
+		<div class="col-sm-12">
+			<p class="text-muted">{%= help %}</p><br>
+			<div class="form"></div>
+		</div>
+	</div>
+	<br>
+	<div class="footer">
+		<div>
+            <a class="prev-btn hide btn btn-default btn-sm">{%= __("Previous") %}</a>
+			<a class="next-btn hide btn btn-primary btn-sm">{%= __("Next") %}</a>
+			<a class="complete-btn hide btn btn-primary btn-sm"><b>{%= __("Complete Setup") %}</b></a>
+		</div>
+	</div>
+    <br><br>
+</div>
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index bfa3e39..8d00f94 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -205,7 +205,7 @@
    "width": "100px"
   }, 
   {
-   "fieldname": "sec_break25", 
+   "fieldname": "cusrrency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -435,6 +435,15 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "other_charges_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Taxes and Charges Total", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Taxes and Charges Total (Company Currency)", 
@@ -453,22 +462,23 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "other_charges_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Taxes and Charges Total", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "label": "Totals", 
@@ -1014,7 +1024,7 @@
  "idx": 1, 
  "in_create": 0, 
  "is_submittable": 1, 
- "modified": "2015-01-06 17:34:32.623408", 
+ "modified": "2015-01-15 07:33:24.245923", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index d77cd1d..8c74f09 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -390,7 +390,7 @@
 			if not frappe.db.exists("Item", newdn):
 				frappe.throw(_("Item {0} does not exist").format(newdn))
 
-			field_list = ["stock_uom", "is_stock_item", "has_serial_no", "has_batch_no"]
+			field_list = ["stock_uom", "is_stock_item", "has_serial_no", "has_batch_no", "is_manufactured_item"]
 			new_properties = [cstr(d) for d in frappe.db.get_value("Item", newdn, field_list)]
 			if new_properties != [cstr(self.get(fld)) for fld in field_list]:
 				frappe.throw(_("To merge, following properties must be same for both items")
diff --git a/erpnext/stock/doctype/item_attribute/item_attribute.json b/erpnext/stock/doctype/item_attribute/item_attribute.json
index d41646c..ce0190d 100644
--- a/erpnext/stock/doctype/item_attribute/item_attribute.json
+++ b/erpnext/stock/doctype/item_attribute/item_attribute.json
@@ -1,7 +1,7 @@
 {
  "allow_copy": 0, 
  "allow_import": 1, 
- "allow_rename": 0, 
+ "allow_rename": 1, 
  "autoname": "field:attribute_name", 
  "creation": "2014-09-26 03:49:54.899170", 
  "custom": 0, 
@@ -54,7 +54,7 @@
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
- "modified": "2014-09-26 06:08:28.729519", 
+ "modified": "2015-01-15 15:25:52.728797", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item Attribute", 
diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.js b/erpnext/stock/doctype/packing_slip/packing_slip.js
index ff02e84..6769845 100644
--- a/erpnext/stock/doctype/packing_slip/packing_slip.js
+++ b/erpnext/stock/doctype/packing_slip/packing_slip.js
@@ -8,12 +8,15 @@
 }
 
 
-cur_frm.fields_dict['items'].grid.get_field('item_code').get_query =
-		function(doc, cdt, cdn) {
-			return {
-				query: "erpnext.stock.doctype.packing_slip.packing_slip.item_details",
-				filters:{ 'delivery_note': doc.delivery_note}
-			}
+cur_frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
+	if(!doc.delivery_note) {
+		frappe.throw(__("Please Delivery Note first"))
+	} else {
+		return {
+			query: "erpnext.stock.doctype.packing_slip.packing_slip.item_details",
+			filters:{ 'delivery_note': doc.delivery_note}
+		}
+	}
 }
 
 cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index 2618de2..9a84d3d 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -131,7 +131,7 @@
    "width": "100px"
   }, 
   {
-   "fieldname": "currency_price_list", 
+   "fieldname": "currency_and_price_list", 
    "fieldtype": "Section Break", 
    "label": "Currency and Price List", 
    "options": "icon-tag", 
@@ -767,7 +767,7 @@
  "icon": "icon-truck", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2015-01-06 17:40:23.838112", 
+ "modified": "2015-01-15 07:34:39.475183", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Purchase Receipt", 
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index 32de53d..b82fe4b 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -987,6 +987,8 @@
 		"incoming_rate": args.incoming_rate,
 		"conversion_factor": 1.0
 	})
+	s.posting_date= "2013-01-01"
+	s.fiscal_year= "_Test Fiscal Year 2013"
 	s.insert()
 	s.submit()
 	return s
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 530ab9a..9c85277 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -153,8 +153,8 @@
 				if row.valuation_rate in ("", None):
 					row.valuation_rate = previous_sle.get("valuation_rate")
 
-			# if row.qty and not row.valuation_rate:
-			# 	frappe.throw(_("Valuation Rate required for Item {0}").format(row.item_code))
+			if row.qty and not row.valuation_rate:
+				frappe.throw(_("Valuation Rate required for Item {0}").format(row.item_code))
 
 			self.insert_entries(row)
 
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index c834007..9d0f3b8 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _, throw
-from frappe.utils import flt, cint, add_days
+from frappe.utils import flt, cint, add_days, cstr
 import json
 from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
 from erpnext.setup.utils import get_exchange_rate
@@ -147,7 +147,7 @@
 	out = frappe._dict({
 		"item_code": item.name,
 		"item_name": item.item_name,
-		"description": item.description_html or item.description,
+		"description": cstr(item.description_html).strip() or cstr(item.description).strip(),
 		"warehouse": user_default_warehouse or args.warehouse or item.default_warehouse,
 		"income_account": get_default_income_account(args, item),
 		"expense_account": get_default_expense_account(args, item),
diff --git a/erpnext/utilities/doctype/address_template/address_template.json b/erpnext/utilities/doctype/address_template/address_template.json
index 78af51d..db81511 100644
--- a/erpnext/utilities/doctype/address_template/address_template.json
+++ b/erpnext/utilities/doctype/address_template/address_template.json
@@ -1,57 +1,58 @@
 {
- "autoname": "field:country",
- "creation": "2014-06-05 02:22:36.029850",
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "Master",
+ "allow_rename": 1, 
+ "autoname": "field:country", 
+ "creation": "2014-06-05 02:22:36.029850", 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "Master", 
  "fields": [
   {
-   "fieldname": "country",
-   "fieldtype": "Link",
-   "in_list_view": 1,
-   "label": "Country",
-   "options": "Country",
-   "permlevel": 0,
-   "reqd": 1,
+   "fieldname": "country", 
+   "fieldtype": "Link", 
+   "in_list_view": 1, 
+   "label": "Country", 
+   "options": "Country", 
+   "permlevel": 0, 
+   "reqd": 1, 
    "search_index": 1
-  },
+  }, 
   {
-   "description": "This format is used if country specific format is not found",
-   "fieldname": "is_default",
-   "fieldtype": "Check",
-   "in_list_view": 1,
-   "label": "Is Default",
+   "description": "This format is used if country specific format is not found", 
+   "fieldname": "is_default", 
+   "fieldtype": "Check", 
+   "in_list_view": 1, 
+   "label": "Is Default", 
    "permlevel": 0
-  },
+  }, 
   {
-   "default": "{{ address_line1 }}<br>{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif -%}\n{% if pincode %}{{ pincode }}<br>{% endif -%}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif -%}\n{% if fax %}Fax: {{ fax }}<br>{% endif -%}\n{% if email_id %}Email: {{ email_id }}<br>{% endif -%}\n",
-   "description": "<h4>Default Template</h4>\n<p>Uses <a href=\"http://jinja.pocoo.org/docs/templates/\">Jinja Templating</a> and all the fields of Address (including Custom Fields if any) will be available</p>\n<pre><code>{{ address_line1 }}&lt;br&gt;\n{% if address_line2 %}{{ address_line2 }}&lt;br&gt;{% endif -%}\n{{ city }}&lt;br&gt;\n{% if state %}{{ state }}&lt;br&gt;{% endif -%}\n{% if pincode %} PIN:  {{ pincode }}&lt;br&gt;{% endif -%}\n{{ country }}&lt;br&gt;\n{% if phone %}Phone: {{ phone }}&lt;br&gt;{% endif -%}\n{% if fax %}Fax: {{ fax }}&lt;br&gt;{% endif -%}\n{% if email_id %}Email: {{ email_id }}&lt;br&gt;{% endif -%}\n</code></pre>",
-   "fieldname": "template",
-   "fieldtype": "Code",
-   "label": "Template",
+   "default": "{{ address_line1 }}<br>{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif -%}\n{% if pincode %}{{ pincode }}<br>{% endif -%}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif -%}\n{% if fax %}Fax: {{ fax }}<br>{% endif -%}\n{% if email_id %}Email: {{ email_id }}<br>{% endif -%}\n", 
+   "description": "<h4>Default Template</h4>\n<p>Uses <a href=\"http://jinja.pocoo.org/docs/templates/\">Jinja Templating</a> and all the fields of Address (including Custom Fields if any) will be available</p>\n<pre><code>{{ address_line1 }}&lt;br&gt;\n{% if address_line2 %}{{ address_line2 }}&lt;br&gt;{% endif -%}\n{{ city }}&lt;br&gt;\n{% if state %}{{ state }}&lt;br&gt;{% endif -%}\n{% if pincode %} PIN:  {{ pincode }}&lt;br&gt;{% endif -%}\n{{ country }}&lt;br&gt;\n{% if phone %}Phone: {{ phone }}&lt;br&gt;{% endif -%}\n{% if fax %}Fax: {{ fax }}&lt;br&gt;{% endif -%}\n{% if email_id %}Email: {{ email_id }}&lt;br&gt;{% endif -%}\n</code></pre>", 
+   "fieldname": "template", 
+   "fieldtype": "Code", 
+   "label": "Template", 
    "permlevel": 0
   }
- ],
- "icon": "icon-map-marker",
- "modified": "2014-08-18 06:14:15.200689",
- "modified_by": "Administrator",
- "module": "Utilities",
- "name": "Address Template",
- "name_case": "",
- "owner": "Administrator",
+ ], 
+ "icon": "icon-map-marker", 
+ "modified": "2015-01-15 15:25:18.709952", 
+ "modified_by": "Administrator", 
+ "module": "Utilities", 
+ "name": "Address Template", 
+ "name_case": "", 
+ "owner": "Administrator", 
  "permissions": [
   {
-   "create": 1,
-   "delete": 1,
-   "export": 1,
-   "permlevel": 0,
-   "read": 1,
-   "report": 1,
-   "role": "System Manager",
-   "set_user_permissions": 1,
+   "create": 1, 
+   "delete": 1, 
+   "export": 1, 
+   "permlevel": 0, 
+   "read": 1, 
+   "report": 1, 
+   "role": "System Manager", 
+   "set_user_permissions": 1, 
    "write": 1
   }
- ],
- "sort_field": "modified",
+ ], 
+ "sort_field": "modified", 
  "sort_order": "DESC"
-}
+}
\ No newline at end of file
diff --git a/erpnext/utilities/repost_stock.py b/erpnext/utilities/repost_stock.py
index 5f18647..df7d82b 100644
--- a/erpnext/utilities/repost_stock.py
+++ b/erpnext/utilities/repost_stock.py
@@ -242,7 +242,7 @@
 				doc.validate()
 
 			doc.update_stock_ledger()
-			doc.make_gl_entries(repost_future_gle=False, allow_negative_stock=True)
+			doc.make_gl_entries(repost_future_gle=False)
 			frappe.db.commit()
 		except Exception, e:
 			print frappe.get_traceback()