Skip to content

Commit

Permalink
[IMP] add rename_fields_cr, keep rename_fields for backwards compatib…
Browse files Browse the repository at this point in the history
…ility
  • Loading branch information
sbidoul committed Nov 24, 2023
1 parent dcb78a4 commit 4ff74cb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,16 @@ def rename_columns(cr, column_spec):


def rename_fields(env, field_spec, no_deep=False):
"""Rename fields. Typically called in the pre script. WARNING: If using
this on base module, pass the argument ``no_deep`` with True value for
avoiding the using of the environment (which is not yet loaded).
"""Rename fields. See rename_fields_cr for details.
:param no_deep: If True, avoids to perform any operation that involves
the environment. Not used for now.
"""
return rename_fields_cr(env.cr, field_spec)


def rename_fields_cr(cr, field_spec):
"""Rename fields. Typically called in the pre script.
This, in contrast of ``rename_columns``, performs all the steps for
completely rename a field from one name to another. This is needed for
Expand All @@ -655,12 +662,7 @@ def rename_fields(env, field_spec, no_deep=False):
* Table name. The name of the SQL table for the model.
* Old field name. The name of the old field.
* New field name. The name of the new field.
:param no_deep: If True, avoids to perform any operation that involves
the environment. Not used for now.
"""
# This method has never implemented Environment usage apart cursor.
# To keep backward compatibility, check if env == Environment
cr = env.cr if isinstance(env, core.api.Environment) else env
for model, table, old_field, new_field in field_spec:
if column_exists(cr, table, old_field):
rename_columns(cr, {table: [(old_field, new_field)]})
Expand Down

0 comments on commit 4ff74cb

Please sign in to comment.