diff --git a/openupgrade_scripts/scripts/base/16.0.1.3/end-migration.py b/openupgrade_scripts/scripts/base/16.0.1.3/end-migration.py index 3afb9085e12b..24e446a5c8b3 100644 --- a/openupgrade_scripts/scripts/base/16.0.1.3/end-migration.py +++ b/openupgrade_scripts/scripts/base/16.0.1.3/end-migration.py @@ -10,7 +10,7 @@ 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.* name and help are merged in the base post-migration ("ir.actions.act_window", "name"), ("ir.actions.act_window", "help"), ("ir.actions.act_url", "name"), diff --git a/openupgrade_scripts/scripts/base/16.0.1.3/post-migration.py b/openupgrade_scripts/scripts/base/16.0.1.3/post-migration.py index 4736c4473194..23f24bd41b5d 100644 --- a/openupgrade_scripts/scripts/base/16.0.1.3/post-migration.py +++ b/openupgrade_scripts/scripts/base/16.0.1.3/post-migration.py @@ -1,7 +1,36 @@ # Copyright 2023 Hunki Enterprises BV (https://hunki-enterprises.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openupgradelib import openupgrade +from openupgradelib import openupgrade, openupgrade_160 + +from odoo.tools import column_exists + + +def update_ir_actions_translations(env): + """Merge the translations of the name and help of ir.actions.* models. + + Those columns are inherited from ir.actions.actions: once translated + (jsonb), the ORM converts them keeping only the en_US value. The + pre-migration excludes them, so merge the ir_translation records here, + while that table is still available (end-migration scripts run after the + migration tests). + """ + fields_spec = [ + (model_name, field_name) + for model_name in ( + "ir.actions.act_window", + "ir.actions.act_url", + "ir.actions.server", + "ir.actions.client", + "ir.actions.report", + ) + for field_name in ("name", "help") + if model_name in env + and field_name in env[model_name]._fields + and env[model_name]._fields[field_name].translate + and column_exists(env.cr, env[model_name]._table, field_name) + ] + openupgrade_160.migrate_translations_to_jsonb(env, fields_spec) @openupgrade.migrate() @@ -11,3 +40,4 @@ def migrate(env, version): "UPDATE res_partner p SET company_registry=c.company_registry " "FROM res_company c WHERE c.partner_id=p.id" ) + update_ir_actions_translations(env) diff --git a/openupgrade_scripts/scripts/base/16.0.1.3/tests/data.py b/openupgrade_scripts/scripts/base/16.0.1.3/tests/data.py index 3a6320e3e6e6..021cfd92f1f0 100644 --- a/openupgrade_scripts/scripts/base/16.0.1.3/tests/data.py +++ b/openupgrade_scripts/scripts/base/16.0.1.3/tests/data.py @@ -1,4 +1,42 @@ +from odoo import fields + env = locals().get("env") # set company_registry in v15 to be sure we migrate it correctly to v16 env.ref("base.main_company").company_registry = "424242" + +# translated name and help of a user-created scheduled action: ir.actions.* +# translations are excluded from the generic pre-migration update, the base +# post-migration must merge them +action = env["ir.actions.server"].create( + { + "name": "OpenUpgrade Test Action", + "help": "
OpenUpgrade action help
", + "model_id": env.ref("base.model_res_partner").id, + "state": "code", + "code": "pass", + } +) +env["ir.cron"].create( + { + "ir_actions_server_id": action.id, + "cron_name": "OpenUpgrade Test Action", + "user_id": env.uid, + "interval_number": 1, + "interval_type": "months", + "nextcall": fields.Datetime.now(), + } +) +action.with_context(lang="fr_FR").write({"name": "Action de test OpenUpgrade"}) +# the html help is translated term by term, as in v15 for callable translations +env["ir.translation"].create( + { + "type": "model_terms", + "name": "ir.actions.server,help", + "res_id": action.id, + "lang": "fr_FR", + "src": "OpenUpgrade action help", + "value": "Aide OpenUpgrade", + "state": "translated", + } +) env.cr.commit() diff --git a/openupgrade_scripts/scripts/base/16.0.1.3/tests/test_base_migration.py b/openupgrade_scripts/scripts/base/16.0.1.3/tests/test_base_migration.py index 060eff2d75e4..7fa26b18b5a6 100644 --- a/openupgrade_scripts/scripts/base/16.0.1.3/tests/test_base_migration.py +++ b/openupgrade_scripts/scripts/base/16.0.1.3/tests/test_base_migration.py @@ -14,3 +14,24 @@ def test_translations(self): title_mister = self.env.ref("base.res_partner_title_mister") self.assertEqual(title_mister.name, "Mister") self.assertEqual(title_mister.with_context(lang="fr_FR").name, "Monsieur") + + def test_ir_actions_translations(self): + """The name and help of ir.actions.* records keep their translations. + + Their columns become jsonb keeping only en_US, and the pre-migration + excludes them from the generic translation migration. + """ + action = self.env["ir.actions.server"].search( + [("name", "=", "OpenUpgrade Test Action")], limit=1 + ) + self.assertTrue(action, "The test server action is missing") + action_fr = action.with_context(lang="fr_FR") + self.assertEqual(action_fr.name, "Action de test OpenUpgrade") + self.assertIn("Aide OpenUpgrade", action_fr.help) + cron = self.env["ir.cron"].search( + [("ir_actions_server_id", "=", action.id)], limit=1 + ) + self.assertTrue(cron, "The test scheduled action is missing") + self.assertEqual( + cron.with_context(lang="fr_FR").name, "Action de test OpenUpgrade" + ) diff --git a/openupgrade_scripts/scripts/base/16.0.1.3/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/base/16.0.1.3/upgrade_analysis_work.txt index 19f8a77bc847..de5b9c1d20b3 100644 --- a/openupgrade_scripts/scripts/base/16.0.1.3/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/base/16.0.1.3/upgrade_analysis_work.txt @@ -2,8 +2,10 @@ obsolete model base.update.translations [transient] obsolete model ir.translation -# PARTIALLY DONE for fields with translate=True (plain text) -# TODO translations of fields with translate=callable (html etc) +# PARTIALLY DONE for fields with translate=True (plain text), including the +# name of the ir.actions.* models in the post-migration +# TODO translations of fields with translate=callable (html etc), except the +# help of the ir.actions.* models, done in the post-migration new model change.password.own [transient] new model ir.binary [abstract]