diff options
| author | Martin Trigaux <mat@odoo.com> | 2018-12-26 10:30:44 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-02-08 12:27:15 +0000 |
| commit | 288b5e3a41420313a2adb25603d7a7fc7b009a3b (patch) | |
| tree | b55850a5ec221373b678e5d8a2d2fa63a492b175 /addons/website_theme_install/models/ir_module_module.py | |
| parent | 6c099e9d21854c96ba28bb3884de78cad0515fe9 (diff) | |
[FIX] website_theme: translate website themes
Inspired by l10n_multilang
When a theme is installed, the theme.* records are used to generate actual records.
The same was as we use account.account.template to create account.account, the
translations of the theme records should be propagated to the new records.
opw-1918120
closes odoo/odoo#29748
Diffstat (limited to 'addons/website_theme_install/models/ir_module_module.py')
| -rw-r--r-- | addons/website_theme_install/models/ir_module_module.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/addons/website_theme_install/models/ir_module_module.py b/addons/website_theme_install/models/ir_module_module.py index 55f77590c6b..e1b7489f7c5 100644 --- a/addons/website_theme_install/models/ir_module_module.py +++ b/addons/website_theme_install/models/ir_module_module.py @@ -25,6 +25,10 @@ class IrModuleModule(models.Model): ('website.menu', 'theme.website.menu'), ('ir.attachment', 'theme.ir.attachment'), ]) + _theme_translated_fields = { + 'theme.ir.ui.view': [('theme.ir.ui.view,arch', 'ir.ui.view,arch_db')], + 'theme.website.menu': [('theme.website.menu,name', 'website.menu,name')], + } image_ids = fields.One2many('ir.attachment', 'res_id', domain=[('res_model', '=', _name), ('mimetype', '=like', 'image/%')], @@ -162,8 +166,10 @@ class IrModuleModule(models.Model): if 'active' in rec_data: rec_data.pop('active') find.update(rec_data) + self._post_copy(rec, find) else: - self.env[model_name].create(rec_data) + new_rec = self.env[model_name].create(rec_data) + self._post_copy(rec, new_rec) remaining -= rec @@ -175,6 +181,20 @@ class IrModuleModule(models.Model): self._theme_cleanup(model_name, website) @api.multi + def _post_copy(self, old_rec, new_rec): + self.ensure_one() + translated_fields = self._theme_translated_fields.get(old_rec._name, []) + for (src_field, dst_field) in translated_fields: + self._cr.execute("""INSERT INTO ir_translation (lang, src, name, res_id, state, value, type, module) + SELECT t.lang, t.src, %s, %s, t.state, t.value, t.type, t.module + FROM ir_translation t + WHERE name = %s + AND res_id = %s + ON CONFLICT DO NOTHING""", + (dst_field, new_rec.id, src_field, old_rec.id)) + + + @api.multi def _theme_load(self, website): """ For every type of model in ``self._theme_model_names``, and for every theme in ``self``: |
