Skip to content
Open
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
2 changes: 1 addition & 1 deletion openupgrade_scripts/scripts/base/16.0.1.3/end-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
32 changes: 31 additions & 1 deletion openupgrade_scripts/scripts/base/16.0.1.3/post-migration.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
38 changes: 38 additions & 0 deletions openupgrade_scripts/scripts/base/16.0.1.3/tests/data.py
Original file line number Diff line number Diff line change
@@ -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": "<p>OpenUpgrade action help</p>",
"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()
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading