Replace renamed fields in custom script and custom print formats

This commit is contained in:
Nabin Hait 2015-02-12 11:48:50 +05:30
parent 56e6ad2112
commit 031303d719

View File

@ -0,0 +1,54 @@
# 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
renamed_fields = get_all_renamed_fields()
for dt, script_field in (("Custom Script", "script"), ("Print Format", "html")):
cond1 = " or ".join("""{0} like "%%{1}%%" """.format(script_field, d[0].replace("_", "\\_")) for d in renamed_fields)
cond2 = " and standard = 'No'" if dt == "Print Format" else ""
for name, script in frappe.db.sql("select name, {0} as script from `tab{1}` where ({2}) {3}".format(script_field, dt, cond1, cond2)):
update_script(dt, name, script_field, script, renamed_fields)
def get_all_renamed_fields():
from erpnext.patches.v5_0.rename_table_fieldnames import rename_map
renamed_fields = (
("net_total", "base_net_total"),
("net_total_export", "net_total"),
("net_total_import", "net_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"),
("other_charges_added_import", "taxes_and_charges_added"),
("other_charges_deducted", "base_taxes_and_charges_deducted"),
("other_charges_deducted_import", "taxes_and_charges_deducted"),
("total_tax", "base_total_taxes_and_charges"),
("grand_total", "base_grand_total"),
("grand_total_export", "grand_total"),
("grand_total_import", "grand_total"),
("rounded_total", "base_rounded_total"),
("rounded_total_export", "rounded_total"),
("rounded_total_import", "rounded_total"),
("in_words", "base_in_words"),
("in_words_export", "in_words"),
("in_words_import", "in_words")
)
for fields in rename_map.values():
renamed_fields += fields
return renamed_fields
def update_script(dt, name, script_field, script, renamed_fields):
for from_field, to_field in renamed_fields:
script = re.sub(r"\b{}\b".format(from_field), to_field, script)
frappe.db.set_value(dt, name, script_field, script)