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

[IMP] openupgrade_160, openupgrade_tools: BS4 to BS5 transformation yeahhhhh #1

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
76cda7a
[FIX] delete_record_translation: invalid input syntax for type json
ndd-odoo Jul 5, 2023
b354ed4
Merge pull request #335 from duong77476/master_fix_delete_record_tran…
MiquelRForgeFlow Jul 5, 2023
9599992
[UPD] HTML documentation
github-actions[bot] Jul 5, 2023
86aca62
[FIX] delete_record_translations: error when only update for 1 one
ndd-odoo Jul 6, 2023
ea53875
Merge pull request #337 from duong77476/master_fix_delete_record_tran…
MiquelRForgeFlow Jul 6, 2023
bb6dbfe
[UPD] HTML documentation
github-actions[bot] Jul 6, 2023
88973d2
[ADD] get_model2table: method to map nonstandard table names
MiquelRForgeFlow Jul 5, 2023
7819744
Merge pull request #336 from ForgeFlow/master-add-get_model2table
pedrobaeza Jul 14, 2023
66c1f84
[UPD] HTML documentation
github-actions[bot] Jul 14, 2023
b63812a
[FIX] merge_records: assure don't break on method="orm" if KeyError o…
MiquelRForgeFlow Jul 17, 2023
fb09131
Merge pull request #340 from ForgeFlow/master-minor-fix-merge
pedrobaeza Jul 17, 2023
d6a7093
[UPD] HTML documentation
github-actions[bot] Jul 17, 2023
f411bf2
[IMP] Merge records: add first_not_null operation on int,float,moneta…
marielejeune Aug 9, 2023
52841c8
[IMP] Replace deprecated recompute() in version 16
marielejeune Aug 10, 2023
47e566b
[FIX] fix columns in delete_record_translations()
huguesdk Aug 28, 2023
ddce67b
Merge pull request #342 from coopiteasy/fix_delete_translation_column…
pedrobaeza Aug 28, 2023
86bd35d
[UPD] HTML documentation
github-actions[bot] Aug 28, 2023
de0fe1f
Merge pull request #341 from acsone/openupgradelib_merge_records_firs…
pedrobaeza Aug 29, 2023
f5be91a
[UPD] HTML documentation
github-actions[bot] Aug 29, 2023
dd46873
[IMP] openupgrade_160, openupgrade_tools: BS4 to BS5 Tranformation
ndd-odoo Jul 10, 2023
b76b002
[IMP] openupgrade_160, openupgrade_tool: special case for class
ndd-odoo Aug 26, 2023
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
38 changes: 29 additions & 9 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
@@ -169,6 +169,7 @@ def do_raise(error):
"update_module_names",
"add_ir_model_fields",
"get_legacy_name",
"get_model2table",
"m2o_to_x2m",
"float_to_integer",
"message",
@@ -875,8 +876,8 @@ def rename_models(cr, model_spec):
"""
for (old, new) in model_spec:
logger.info("model %s: renaming to %s", old, new)
_old = old.replace(".", "_")
_new = new.replace(".", "_")
_old = get_model2table(old)
_new = get_model2table(new)
logged_query(
cr,
"UPDATE ir_model SET model = %s WHERE model = %s",
@@ -996,7 +997,7 @@ def rename_models(cr, model_spec):
)
rows = cr.fetchall()
for row in rows:
table = row[0].replace(".", "_")
table = get_model2table(row[0])
if not table_exists(cr, table):
continue
column = row[1]
@@ -1094,7 +1095,7 @@ def merge_models(cr, old_model, new_model, ref_field):
tables. You should have to do that previously in the migration scripts.
"""
logger.info("model %s: merging to %s", old_model, new_model)
model_table = new_model.replace(".", "_")
model_table = get_model2table(new_model)
renames = [
("ir_attachment", "res_model", "res_id", ""),
("ir_model_data", "model", "res_id", ""),
@@ -1251,7 +1252,7 @@ def rename_xmlids(cr, xmlids_spec, allow_merge=False):
"to the same model (%s, %s)"
% (old, new, old_row[1], new_row[1])
)
table = old_row[1].replace(".", "_")
table = get_model2table(old_row[1])
if not table_exists(cr, table):
do_raise(
"Cannot merge XMLIDs %s, %s because the table I "
@@ -1815,6 +1816,22 @@ def get_legacy_name(original_name):
)


def get_model2table(model):
# map of nonstandard table names
model2table = {
"ir.actions.actions": "ir_actions",
"ir.actions.act_window": "ir_act_window",
"ir.actions.act_window.view": "ir_act_window_view",
"ir.actions.act_window_close": "ir_actions",
"ir.actions.act_url": "ir_act_url",
"ir.actions.server": "ir_act_server",
"ir.actions.client": "ir_act_client",
"ir.actions.report.xml": "ir_act_report_xml", # model < v11
"ir.actions.report": "ir_act_report_xml", # model >= v11
}
return model2table.get(model, model.replace(".", "_"))


def m2o_to_x2m(cr, model, table, field, source_field):
"""
Transform many2one relations into one2many or many2many.
@@ -2644,7 +2661,7 @@ def delete_record_translations(cr, module, xml_ids, field_list=None):
),
)
else:
table = model.replace(".", "_")
table = get_model2table(model)
# we use information_schema to assure the columns exist
cr.execute(
"""
@@ -2875,7 +2892,10 @@ def add_fields(env, field_spec):
init_value = vals[6] if len(vals) > 6 else False
# Add SQL column
if not table_name:
table_name = env[model_name]._table
try:
table_name = env[model_name]._table
except KeyError:
table_name = get_model2table(model_name)
if not column_exists(env.cr, table_name, field_name):
sql_type = sql_type or sql_type_mapping.get(field_type)
if sql_type:
@@ -2965,7 +2985,7 @@ def add_fields(env, field_spec):
# Add ir.model.data entry
if not module or version_info[0] >= 12:
continue
name1 = "field_%s_%s" % (model_name.replace(".", "_"), field_name)
name1 = "field_%s_%s" % (table_name, field_name)
try:
with env.cr.savepoint():
logged_query(
@@ -3090,7 +3110,7 @@ def update_module_moved_models(cr, model, old_module, new_module):
:param old_module: Previous module of the models
:param new_module: New module of the models
"""
table = model.replace(".", "_")
table = get_model2table(model)
logger.info(
"Moving model %s from module '%s' to module '%s'", model, old_module, new_module
)
38 changes: 24 additions & 14 deletions openupgradelib/openupgrade_merge_records.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
from psycopg2.errorcodes import UNDEFINED_COLUMN, UNIQUE_VIOLATION
from psycopg2.extensions import AsIs

from .openupgrade import logged_query, version_info
from .openupgrade import get_model2table, logged_query, version_info
from .openupgrade_tools import column_exists, table_exists

logger = logging.getLogger("OpenUpgrade")
@@ -216,11 +216,11 @@ def _change_reference_refs_sql(
for row in rows:
try:
model = env[row[0]]
if not model._auto: # Discard SQL views
continue
table = model._table
except KeyError:
continue
if not model._auto: # Discard SQL views
continue
table = model._table
table = get_model2table(row[0])
if not table_exists(cr, table):
continue
column = row[1]
@@ -757,9 +757,10 @@ def _change_generic(
]:
try:
model = env[model_to_replace].with_context(active_test=False)
table = model._table
except KeyError:
continue
if (model._table, res_id_column) in exclude_columns:
table = get_model2table(model_to_replace)
if (table, res_id_column) in exclude_columns:
continue
if method == "orm":
if not model._fields.get(model_column) or not model._fields.get(
@@ -794,12 +795,12 @@ def _change_generic(
"Changed %s record(s) of model '%s'", len(records), model_to_replace
)
else:
if not column_exists(
env.cr, model._table, res_id_column
) or not column_exists(env.cr, model._table, model_column):
if not column_exists(env.cr, table, res_id_column) or not column_exists(
env.cr, table, model_column
):
continue
format_args = {
"table": sql.Identifier(model._table),
"table": sql.Identifier(table),
"res_id_column": sql.Identifier(res_id_column),
"model_column": sql.Identifier(model_column),
}
@@ -861,7 +862,10 @@ def _delete_records_sql(
env, model_name, record_ids, target_record_id, model_table=None
):
if not model_table:
model_table = env[model_name]._table
try:
model_table = env[model_name]._table
except KeyError:
model_table = get_model2table(model_name)
logged_query(
env.cr,
"DELETE FROM ir_model_data WHERE model = %s AND res_id IN %s",
@@ -892,7 +896,10 @@ def _delete_records_orm(env, model_name, record_ids, target_record_id):

def _check_recurrence(env, model_name, record_ids, target_record_id, model_table=None):
if not model_table:
model_table = env[model_name]._table
try:
model_table = env[model_name]._table
except KeyError:
model_table = get_model2table(model_name)
env.cr.execute(
"""
SELECT tc.table_name, kcu.column_name, COALESCE(imf.column1, 'id')
@@ -1015,7 +1022,10 @@ def merge_records(
else:
# Check which records to be merged exist
if not model_table:
model_table = env[model_name]._table
try:
model_table = env[model_name]._table
except KeyError:
model_table = get_model2table(model_name)
env.cr.execute(
sql.SQL("SELECT id FROM {} WHERE id IN %s").format(
sql.Identifier(model_table)