From e72c6093064b0321743bb1d24a705718d32d0820 Mon Sep 17 00:00:00 2001
From: Xavier Morel <xmo@odoo.com>
Date: Wed, 29 Apr 2020 12:47:35 +0000
Subject: [PATCH] [FIX] base: translations when dev-mode is enabled

When computing the `arch` from the arch_db, the field gets translated
as a matter of course as `arch_db` is a stored field with a
translation method. This means `arch` is assumed to be in the proper
language in the cache.

However when reading from the filesystem (dev=xml) this is not the
case, and the view XML ends up untranslated.

Fix the issue by applying the translation function from arch_db onto
the stuff we got from the filesystem.

Note: under the assumption that we *do not* want to store translated
archs in arch_db, explicitly set the lang to None when resetting
views.

Task 2059557

closes odoo/odoo#50389

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
---
 odoo/addons/base/models/ir_ui_view.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py
index 892e317d1ead..9eb5ad4fc416 100644
--- a/odoo/addons/base/models/ir_ui_view.py
+++ b/odoo/addons/base/models/ir_ui_view.py
@@ -277,7 +277,11 @@ actual arch.
                 if fullpath:
                     arch_fs = get_view_arch_from_file(fullpath, xml_id)
                     # replace %(xml_id)s, %(xml_id)d, %%(xml_id)s, %%(xml_id)d by the res_id
-                    arch_fs = arch_fs and resolve_external_ids(arch_fs, xml_id).replace('%%', '%')
+                    if arch_fs:
+                        arch_fs = resolve_external_ids(arch_fs, xml_id).replace('%%', '%')
+                        if self.env.context.get('lang'):
+                            tr = self._fields['arch_db'].get_trans_func(view)
+                            arch_fs = tr(view.id, arch_fs)
                 else:
                     _logger.warning("View %s: Full path [%s] cannot be found.", xml_id, view.arch_fs)
                     arch_fs = False
@@ -319,10 +323,10 @@ actual arch.
             if mode == 'soft':
                 arch = view.arch_prev
             elif mode == 'hard' and view.arch_fs:
-                arch = view.with_context(read_arch_from_file=True).arch
+                arch = view.with_context(read_arch_from_file=True, lang=None).arch
             if arch:
                 # Don't save current arch in previous since we reset, this arch is probably broken
-                view.with_context(no_save_prev=True).write({'arch_db': arch})
+                view.with_context(no_save_prev=True, lang=None).write({'arch_db': arch})
 
     @api.depends('write_date')
     def _compute_model_data_id(self):
-- 
GitLab