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

[16.0][FIX] base: keep translations for null src while upgrade #4477

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
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
44 changes: 44 additions & 0 deletions openupgrade_scripts/scripts/base/16.0.1.3/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade, openupgrade_160

from odoo.tools import column_exists


def update_callable_translatable_fields(env):
"""Use Odoo's core method to get complete translations of translated fields with
a callable method for translations (html_translate, xml_translate)"""
exclusions = [
# ir.actions.* inherits the name and help columns from ir.actions.actions
("ir.actions.act_window", "name"),
("ir.actions.act_window", "help"),
("ir.actions.act_url", "name"),
("ir.actions.act_url", "help"),
("ir.actions.server", "name"),
("ir.actions.server", "help"),
("ir.actions.client", "name"),
("ir.actions.client", "help"),
("ir.actions.report", "name"),
("ir.actions.report", "help"),
]
fields = env["ir.model.fields"].search_read(
[("translate", "=", True)], ["model", "name"]
)
fields_spec = [
(f["model"], f["name"])
for f in fields
if (
(f["model"], f["name"]) not in exclusions
and f["model"] in env
and column_exists(env.cr, env[f["model"]]._table, f["name"])
and f["name"] in env[f["model"]]._fields
and callable(env[f["model"]]._fields[f["name"]].translate)
)
]
openupgrade_160.migrate_translations_to_jsonb(env, fields_spec)


@openupgrade.migrate()
def migrate(env, version):
update_callable_translatable_fields(env)
12 changes: 5 additions & 7 deletions openupgrade_scripts/scripts/base/16.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def update_translatable_fields(cr):
continue
# borrowed from odoo/tools/translate.py#_get_translation_upgrade_queries
translation_name = "%s,%s" % (model, field)
emtpy_src = """'{"en_US": ""}'::jsonb"""
openupgrade.logged_query(
cr,
f"""
Expand All @@ -98,8 +99,10 @@ def update_translatable_fields(cr):
GROUP BY it.res_id
)
UPDATE {table} m
SET "{field}" = CASE WHEN t.noupdate IS FALSE THEN t.value || m."{field}"
ELSE m."{field}" || t.value END
SET "{field}" = CASE
WHEN m."{field}" IS NULL THEN {emtpy_src} || t.value
WHEN t.noupdate IS FALSE THEN t.value || m."{field}"
ELSE m."{field}" || t.value END
FROM t
WHERE t.res_id = m.id
""",
Expand All @@ -108,11 +111,6 @@ def update_translatable_fields(cr):
"name": translation_name,
},
)
openupgrade.logged_query(
cr,
"DELETE FROM ir_translation WHERE type = 'model' AND name = %s",
[translation_name],
)


@openupgrade.migrate(use_env=False)
Expand Down
Loading