From 4023e0e62cd5d5aecc4b45febf4be1b3b6748f63 Mon Sep 17 00:00:00 2001 From: Roy Le Date: Fri, 8 Jul 2022 09:04:21 +0700 Subject: [PATCH] [IMP] rename_fields: make a complete renaming of a field with side features: filters --- openupgradelib/openupgrade.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/openupgradelib/openupgrade.py b/openupgradelib/openupgrade.py index 8d328e10..5e107b34 100644 --- a/openupgradelib/openupgrade.py +++ b/openupgradelib/openupgrade.py @@ -679,12 +679,31 @@ def rename_fields(env, field_spec, no_deep=False): AND context ~ %(old_pattern)s """ % { 'old_pattern': ( - r"$$('group_by'|'col_group_by'):([^\]]*)" + r"""$$('group_by'|'col_group_by'|'graph_groupbys' + |'pivot_measures'|'pivot_row_groupby'|'pivot_column_groupby' + ):([\s*][^\]]*)""" r"'%s(:day|:week|:month|:year){0,1}'(.*?\])$$" ) % old_field, 'new_pattern': r"$$\1:\2'%s\3'\4$$" % new_field, }, (model, ), ) + # Examples of replaced contexts: + # {'graph_measure': 'field' + cr.execute(r""" + UPDATE ir_filters + SET context = regexp_replace( + context, %(old_pattern)s, %(new_pattern)s + ) + WHERE model_id = %%s + AND context ~ %(old_pattern)s + """ % { + 'old_pattern': ( + r"$$'graph_measure':([\s*])'%s(:day|:week|:month|:year){0,1}'$$" + ) % old_field, + 'new_pattern': r"$$'graph_measure':\1'%s\2'$$" % new_field, + }, (model, ), + ) + # TODO: Rename when the field in ir_ui_view_custom if table_exists(env.cr, 'mail_alias'): # Rename appearances on mail alias cr.execute("""