Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to update models module #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def do_raise(error):
'logged_query',
'column_exists',
'table_exists',
'update_module_moved_models',
'update_module_moved_fields',
'update_module_names',
'add_ir_model_fields',
Expand Down Expand Up @@ -2452,6 +2453,55 @@ def update_field_multilang(records, field, method):
record[field] = new_value


def update_module_moved_models(cr, model, old_module, new_module):
"""Update module for model definition in general tables that have been
moved from one module to another.
:param cr: Database cursor
:param model: Model name
:param old_module: Previous module of the fields
:param new_module: New module of the fields
"""
logger.info(
"Moving model %s from module '%s' to module '%s'",
model, old_module, new_module
)
values = {
'new_module': new_module,
'old_module': old_module,
'model': model
}
# Update xml-id entries
logged_query(
cr, """
UPDATE ir_model_data imd
SET module = %(new_module)s
FROM ir_model im
WHERE
im.model = %(model)s AND
imd.module = %(old_module)s AND
imd.model = 'ir.model' AND
imd.res_id = im.id AND
imd.id NOT IN (
SELECT id FROM ir_model_data WHERE module = %(new_module)s
)
""", values,
)
# Update model translations
logged_query(
cr, """
UPDATE ir_translation it
SET module = %(new_module)s
FROM ir_model im
WHERE
im.model = %(model)s AND
it.res_id = im.id AND
it.module = %(old_module)s AND
it.name = 'ir.model,name' AND
it.type = 'model'
""", values,
)


def update_module_moved_fields(
cr, model, moved_fields, old_module, new_module):
"""Update module for field definition in general tables that have been
Expand Down