Merge branch 'develop'
diff --git a/erpnext/__version__.py b/erpnext/__version__.py
index 6b4f893..6d0efc7 100644
--- a/erpnext/__version__.py
+++ b/erpnext/__version__.py
@@ -1,2 +1,2 @@
 from __future__ import unicode_literals
-__version__ = 'v5.0.0'
\ No newline at end of file
+__version__ = 'v5.0.0'
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 22e0a38..d166638 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -216,7 +216,7 @@
 // ------------
 cur_frm.cscript.hide_fields = function(doc) {
 	par_flds = ['project_name', 'due_date', 'is_opening', 'source', 'total_advance', 'get_advances_received',
-	'advances', 'sales_partner', 'commission_rate', 'total_commission', 'advances', 'from_date', 'to_date'];
+		'advances', 'sales_partner', 'commission_rate', 'total_commission', 'advances', 'from_date', 'to_date'];
 
 	if(cint(doc.is_pos) == 1) {
 		hide_field(par_flds);
diff --git a/erpnext/accounts/page/accounts_browser/accounts_browser.py b/erpnext/accounts/page/accounts_browser/accounts_browser.py
index bb64e54..593794a 100644
--- a/erpnext/accounts/page/accounts_browser/accounts_browser.py
+++ b/erpnext/accounts/page/accounts_browser/accounts_browser.py
@@ -22,7 +22,7 @@
 	# root
 	if args['parent'] in ("Accounts", "Cost Centers"):
 		select_cond = ", root_type, report_type" if args["parent"]=="Accounts" else ""
-		
+
 		acc = frappe.db.sql(""" select
 			name as value, is_group as expandable %s
 			from `tab%s`
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 07d5e51..8a954a6 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -207,6 +207,22 @@
 	add_to_list(None, 0)
 
 	return filtered_accounts, accounts_by_name
+	
+def sort_root_accounts(roots):
+	"""Sort root types as Asset, Liability, Equity, Income, Expense"""
+
+	def compare_roots(a, b):
+		if a.report_type != b.report_type and a.report_type == "Balance Sheet":
+			return -1
+		if a.root_type != b.root_type and a.root_type == "Asset":
+			return -1
+		if a.root_type == "Liability" and b.root_type == "Equity":
+			return -1
+		if a.root_type == "Income" and b.root_type == "Expense":
+			return -1
+		return 1
+
+	roots.sort(compare_roots)
 
 def sort_root_accounts(roots):
 	"""Sort root types as Asset, Liability, Equity, Income, Expense"""
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py
index 21791f7..476aa92 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.py
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.py
@@ -70,7 +70,7 @@
 			if not (obj.doctype=="Material Request" and getattr(obj, "material_request_type", None)=="Material Transfer"):
 				if item[0][1] != 'Yes' and item[0][2] != 'Yes':
 					frappe.throw(_("{0} must be a Purchased or Sub-Contracted Item in row {1}").format(d.item_code, d.idx))
-			
+
 			items.append(cstr(d.item_code))
 		if items and len(items) != len(set(items)):
 			frappe.msgprint(_("Warning: Same item has been entered multiple times."))
diff --git a/erpnext/manufacturing/report/completed_production_orders/completed_production_orders.json b/erpnext/manufacturing/report/completed_production_orders/completed_production_orders.json
index 3c16810..6e383a1 100644
--- a/erpnext/manufacturing/report/completed_production_orders/completed_production_orders.json
+++ b/erpnext/manufacturing/report/completed_production_orders/completed_production_orders.json
@@ -5,7 +5,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2015-04-24 21:04:02.944586", 
+ "modified": "2015-05-15 05:42:42.742398", 
  "modified_by": "Administrator", 
  "module": "Manufacturing", 
  "name": "Completed Production Orders", 
diff --git a/erpnext/manufacturing/report/open_production_orders/open_production_orders.json b/erpnext/manufacturing/report/open_production_orders/open_production_orders.json
index 860f81d..d40b8ad 100644
--- a/erpnext/manufacturing/report/open_production_orders/open_production_orders.json
+++ b/erpnext/manufacturing/report/open_production_orders/open_production_orders.json
@@ -5,7 +5,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2015-04-23 03:26:35.711681", 
+ "modified": "2015-05-15 05:43:59.976254", 
  "modified_by": "Administrator", 
  "module": "Manufacturing", 
  "name": "Open Production Orders", 
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index d21b955..185a915 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -154,4 +154,4 @@
 erpnext.patches.v5_0.reclculate_planned_operating_cost_in_production_order
 erpnext.patches.v5_0.repost_requested_qty
 erpnext.patches.v5_0.fix_taxes_and_totals_in_party_currency
-erpnext.patches.v5_0.update_tax_amount_after_discount_in_purchase_cycle
\ No newline at end of file
+erpnext.patches.v5_0.update_tax_amount_after_discount_in_purchase_cycle
diff --git a/erpnext/patches/v4_2/repost_requested_qty.py b/erpnext/patches/v4_2/repost_requested_qty.py
new file mode 100644
index 0000000..8c1d6f7
--- /dev/null
+++ b/erpnext/patches/v4_2/repost_requested_qty.py
@@ -0,0 +1,21 @@
+# 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
+
+def execute():
+	from erpnext.utilities.repost_stock import update_bin_qty, get_indented_qty
+
+	count=0
+	for item_code, warehouse in frappe.db.sql("""select distinct item_code, warehouse 
+		from `tabMaterial Request Item` where docstatus = 1"""):
+			try:
+				count += 1
+				update_bin_qty(item_code, warehouse, {
+					"indented_qty": get_indented_qty(item_code, warehouse),
+				})
+				if count % 200 == 0:
+					frappe.db.commit()
+			except:
+				frappe.db.rollback()
diff --git a/erpnext/patches/v4_2/update_advance_paid.py b/erpnext/patches/v4_2/update_advance_paid.py
new file mode 100644
index 0000000..818735a
--- /dev/null
+++ b/erpnext/patches/v4_2/update_advance_paid.py
@@ -0,0 +1,13 @@
+# 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
+
+def execute():
+	for dt in ("Sales Order", "Purchase Order"):
+		orders_with_advance = frappe.db.sql("""select name from `tab{0}` 
+			where docstatus < 2 and ifnull(advance_paid, 0) != 0""".format(dt), as_dict=1)
+			
+		for order in orders_with_advance:
+			frappe.get_doc(dt, order.name).set_total_advance_paid()
\ No newline at end of file
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index b4965ee..a96f5e9 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -238,7 +238,7 @@
 
 		var company_currency = this.get_company_currency();
 		// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
-		if(this.frm.doc.currency !== company_currency  && !this.frm.doc.ignore_pricing_rule) {
+		if(this.frm.doc.currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
 			this.get_exchange_rate(this.frm.doc.currency, company_currency,
 				function(exchange_rate) {
 					me.frm.set_value("conversion_rate", exchange_rate);
diff --git a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
index 0395987..c6ef82f 100644
--- a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
+++ b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
@@ -11,6 +11,8 @@
 	
 	float_precision = cint(frappe.db.get_default("float_precision")) or 3
 
+	float_precision = cint(frappe.db.get_default("float_precision")) or 3
+	
 	columns = get_columns(filters)
 	item_map = get_item_details(filters)
 	iwb_map = get_item_warehouse_batch_map(filters, float_precision)