[patch] Set party account currency in existing orders
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 7b07997..f0e12e0 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -245,3 +245,4 @@
 erpnext.patches.v6_16.update_billing_status_in_dn_and_pr
 erpnext.patches.v6_16.create_manufacturer_records
 execute:frappe.db.sql("update `tabPricing Rule` set title=name where title='' or title is null") #2016-01-27
+erpnext.patches.v6_20.set_party_account_currency_in_orders
\ No newline at end of file
diff --git a/erpnext/patches/v6_20/__init__.py b/erpnext/patches/v6_20/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v6_20/__init__.py
diff --git a/erpnext/patches/v6_20/set_party_account_currency_in_orders.py b/erpnext/patches/v6_20/set_party_account_currency_in_orders.py
new file mode 100644
index 0000000..ae7ad95
--- /dev/null
+++ b/erpnext/patches/v6_20/set_party_account_currency_in_orders.py
@@ -0,0 +1,24 @@
+# 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 doctype in ("Sales Order", "Purchase Order"):
+		frappe.reload_doctype(doctype)
+		
+		for order in frappe.db.sql("""select name, {0} as party from `tab{1}` 
+			where advance_paid > 0 and docstatus=1"""
+			.format(("customer" if doctype=="Sales Order" else "supplier"), doctype), as_dict=1):
+			
+			party_account_currency = frappe.db.get_value("Journal Entry Account", {
+				"reference_type": doctype,
+				"reference_name": order.name,
+				"party": order.party,
+				"docstatus": 1,
+				"is_advance": "Yes"
+			}, "account_currency")
+			
+			frappe.db.set_value(doctype, order.name, "party_account_currency", party_account_currency)
+		
\ No newline at end of file