[FIX] web_editor: Translating a product in the website

Steps to reproduce the bug:
-Change the default lang on the website to be different than en_US
-Edit the name of a product in the website

Bug:
The name of the product is changed in en_US and not in the language
set on the website. The lang is in fact removed from the context in
function saveElement(in addons/web_editor/static/rte.js).

opw:747084
This commit is contained in:
Goffin Simon
2017-06-21 12:02:06 +02:00
parent 18152f35b6
commit 036ccbeff1
2 changed files with 18 additions and 2 deletions
+9 -2
View File
@@ -6,7 +6,7 @@ import logging
from lxml import etree, html
from odoo.exceptions import AccessError
from odoo import api, models
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
@@ -33,6 +33,10 @@ class IrUiView(models.Model):
def extract_embedded_fields(self, arch):
return arch.xpath('//*[@data-oe-model != "ir.ui.view"]')
@api.model
def get_default_lang_code(self):
return False
@api.model
def save_embedded_field(self, el):
Model = self.env[el.get('data-oe-model')]
@@ -44,7 +48,10 @@ class IrUiView(models.Model):
if value is not None:
# TODO: batch writes?
Model.browse(int(el.get('data-oe-id'))).write({field: value})
if self.get_default_lang_code() and field != 'arch' and not isinstance(Model._fields[field], fields.Html):
Model.browse(int(el.get('data-oe-id'))).with_context(lang=self.get_default_lang_code()).write({field: value})
else:
Model.browse(int(el.get('data-oe-id'))).write({field: value})
def _pretty_arch(self, arch):
# remove_blank_string does not seem to work on HTMLParser, and
+9
View File
@@ -146,3 +146,12 @@ class View(models.Model):
if full:
return views
return views.filtered(lambda v: v.customize_show)
@api.model
def get_default_lang_code(self):
website_id = self.env.context.get('website_id')
if website_id:
lang_code = self.env['website'].browse(website_id).default_lang_code
return lang_code
else:
return super(View, self).get_default_lang_code()