From b2b71efb365b08677fb6fa0cd83f4adec28c8da8 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Sat, 20 Jan 2018 21:17:25 +0100 Subject: [PATCH] [BACKPORT] website: translation if website default lang is not en_US Before this commit: When website default lang was not en_US, the translation of fields* in the web_editor would not be saved correctly. Let's illustrate with fr_BE set as main lang: The web_editor's RPC calls does not send language in the context when editing a page (6ebcc06), but it does in translation mode. Note that editing is always performed in the website main lang, fr_BE in this case. Therefore: 1. When EDITING: The backend suppose the language is en_US as there is no lang in the context (hardcoded everywhere). It then write in the record itself instead of the ir.translation as it should since fr_BE is a translation. (In Odoo, every lang is a translation, en_US is always the main lang) 2. When TRANSLATING (in en_US): It would also write on model as the web_editor send the language to the backend when in translate mode. But since en_US is recognized as the main lang (which is correct), it also writes in the model, overriding the incorrect fr_BE writing which was also wrote on the model. This has been fixed in 10.0 with these 2 commits: 036ccbe 2955bf2 With these fixes, the lang is correctly added (by the backend) if the website module is installed. By ensuring the lang is correctly set, the ORM _write() function will process the edition and translation datas as it should: - If it receive en_US, it will write on the model - If it receive another lang, it will write on ir.translation This closes #10883, closes #22403 *Not the HTML/XML fields which are handled differently by the ORM/translation --- addons/web_editor/models/ir_ui_view.py | 6 ++++++ addons/website/models/ir_ui_view.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py index dd7501c44f9..0f326f2e19a 100644 --- a/addons/web_editor/models/ir_ui_view.py +++ b/addons/web_editor/models/ir_ui_view.py @@ -35,12 +35,18 @@ class view(osv.osv): def extract_embedded_fields(self, cr, uid, arch, context=None): return arch.xpath('//*[@data-oe-model != "ir.ui.view"]') + + def get_default_lang_code(self, cr, uid, context=None): + return False + def save_embedded_field(self, cr, uid, el, context=None): Model = self.pool[el.get('data-oe-model')] field = el.get('data-oe-field') converter = self.pool['ir.qweb'].get_converter_for(el.get('data-oe-type')) value = converter.from_html(cr, uid, Model, Model._fields[field], el) + if context and not context.get('lang'): + context['lang'] = self.get_default_lang_code(cr, uid, context=context) if value is not None: # TODO: batch writes? diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 4df13b22c85..01246baaf01 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -228,3 +228,10 @@ class view(osv.osv): 'active': v.active, }) return result + + def get_default_lang_code(self, cr, uid, context): + website_id = context['website_id'] + if website_id: + return self.pool['website'].browse(cr, uid, website_id, context=context).default_lang_code + else: + return super(view, self).get_default_lang_code(cr, uid, context=context)