diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 64cbc4033d..8755837b70 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -57,3 +57,4 @@ execute:frappe.reset_perms("GL Entry") #2014-06-09 execute:frappe.reset_perms("Stock Ledger Entry") #2014-06-09 erpnext.patches.v4_0.create_custom_fields_for_india_specific_fields erpnext.patches.v4_0.save_default_letterhead +erpnext.patches.v4_0.update_custom_print_formats_for_renamed_fields diff --git a/erpnext/patches/v4_0/update_custom_print_formats_for_renamed_fields.py b/erpnext/patches/v4_0/update_custom_print_formats_for_renamed_fields.py new file mode 100644 index 0000000000..60d45cf6a6 --- /dev/null +++ b/erpnext/patches/v4_0/update_custom_print_formats_for_renamed_fields.py @@ -0,0 +1,36 @@ +# 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 +import re + +def execute(): + # NOTE: sequence is important + fields_list = ( + ("amount", "base_amount"), + ("ref_rate", "price_list_rate"), + ("base_ref_rate", "base_price_list_rate"), + ("adj_rate", "discount_percentage"), + ("export_rate", "rate"), + ("basic_rate", "base_rate"), + ("export_amount", "amount"), + ("reserved_warehouse", "warehouse"), + ("import_ref_rate", "price_list_rate"), + ("purchase_ref_rate", "base_price_list_rate"), + ("discount_rate", "discount_percentage"), + ("import_rate", "rate"), + ("purchase_rate", "base_rate"), + ("import_amount", "amount") + ) + + condition = " or ".join("""html like "%%{}%%" """.format(d[0].replace("_", "\\_")) for d in fields_list + if d[0] != "amount") + + for name, html in frappe.db.sql("""select name, html from `tabPrint Format` + where standard = 'No' and ({}) and html not like '%%frappe.%%'""".format(condition)): + html = html.replace("wn.", "frappe.") + for from_field, to_field in fields_list: + html = re.sub(r"\b{}\b".format(from_field), to_field, html) + + frappe.db.set_value("Print Format", name, "html", html)