Patch: taxes and totals in party currency
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 05b92b1..f6ac860 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -112,7 +112,6 @@
 erpnext.patches.v5_0.update_item_name_in_bom
 erpnext.patches.v5_0.rename_customer_issue
 erpnext.patches.v5_0.rename_total_fields
-erpnext.patches.v5_0.replace_renamed_fields_in_custom_script_and_print_formats
 erpnext.patches.v5_0.new_crm_module
 erpnext.patches.v5_0.rename_customer_issue
 erpnext.patches.v5_0.update_material_transfer_for_manufacture
@@ -124,3 +123,5 @@
 erpnext.patches.v5_0.update_projects
 erpnext.patches.v5_0.item_patches
 erpnext.patches.v5_0.update_journal_entry_title
+erpnext.patches.v5_0.taxes_and_totals_in_party_currency
+erpnext.patches.v5_0.replace_renamed_fields_in_custom_scripts_and_print_formats
diff --git a/erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py b/erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py
similarity index 88%
rename from erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py
rename to erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py
index f8775c1..7fe775b 100644
--- a/erpnext/patches/v5_0/replace_renamed_fields_in_custom_script_and_print_formats.py
+++ b/erpnext/patches/v5_0/replace_renamed_fields_in_custom_scripts_and_print_formats.py
@@ -21,9 +21,10 @@
 	from erpnext.patches.v5_0.rename_table_fieldnames import rename_map
 
 	renamed_fields = (
+		("base_amount", "base_net_amount"),
 		("net_total", "base_net_total"),
-		("net_total_export", "net_total"),
-		("net_total_import", "net_total"),
+		("net_total_export", "total"),
+		("net_total_import", "total"),
 		("other_charges_total", "base_total_taxes_and_charges"),
 		("other_charges_total_export", "total_taxes_and_charges"),
 		("other_charges_added", "base_taxes_and_charges_added"),
@@ -39,7 +40,9 @@
 		("rounded_total_import", "rounded_total"),
 		("in_words", "base_in_words"),
 		("in_words_export", "in_words"),
-		("in_words_import", "in_words")
+		("in_words_import", "in_words"),
+		("tax_amount", "base_tax_amount"),
+		("tax_amount_after_discount_amount", "base_tax_amount_after_discount_amount"),
 	)
 
 	for fields in rename_map.values():
diff --git a/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py b/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py
new file mode 100644
index 0000000..b588971
--- /dev/null
+++ b/erpnext/patches/v5_0/taxes_and_totals_in_party_currency.py
@@ -0,0 +1,66 @@
+
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+
+def execute():
+	selling_doctypes = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]
+	buying_doctypes = ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]
+
+	for dt in selling_doctypes:
+		update_values(dt, "Sales Taxes and Charges")
+
+	for dt in buying_doctypes:
+		update_values(dt, "Purchase Taxes and Charges")
+
+def update_values(dt, tax_table):
+	frappe.reload_doctype(dt)
+	frappe.reload_doctype(dt + " Item")
+	frappe.reload_doctype(tax_table)
+
+	# update net_total, discount_on
+	frappe.db.sql("""
+		UPDATE
+			`tab{0}`
+		SET
+			total = net_total,
+			base_total = net_total*conversion_rate,
+			net_total = base_net_total / conversion_rate,
+			apply_discount_on = "Grand Total"
+		WHERE
+			docstatus < 2
+	""".format(dt))
+
+
+	# update net_amount
+	frappe.db.sql("""
+		UPDATE
+			`tab{0}` par, `tab{1}` item
+		SET
+			item.base_net_amount = item.base_amount,
+			item.base_net_rate = item.base_rate,
+			item.net_amount = item.base_net_amount / par.conversion_rate,
+			item.net_rate = item.base_net_rate / par.conversion_rate,
+			item.base_amount = item.amount * par.conversion_rate,
+			item.base_rate = item.rate * par.conversion_rate
+		WHERE
+			par.name = item.parent
+			and par.docstatus < 2
+	""".format(dt, dt + " Item"))
+
+	# update tax in party currency
+	frappe.db.sql("""
+		UPDATE
+			`tab{0}` par, `tab{1}` tax
+		SET
+			tax.base_tax_amount = tax.tax_amount,
+			tax.tax_amount = tax.base_tax_amount / par.conversion_rate,
+			tax.base_total = tax.total,
+			tax.total = tax.base_total / conversion_rate,
+			tax.base_tax_amount_after_discount_amount = tax.tax_amount_after_discount_amount,
+			tax.tax_amount_after_discount_amount = tax.base_tax_amount_after_discount_amount / conversion_rate
+		WHERE
+			par.name = tax.parent
+			and par.docstatus < 2
+	""".format(dt, tax_table))