[FIX] web_editor: crash in date formatting if no langage set
This issue was introduced with commit 251b880de1caeeef1f27447d4ad69e1abeffde19 : in case current user has no langage, we should have a fallback case by retrieving the first langage installed in the database. closes odoo/odoo#46487 X-original-commit: 67cf1150507b8092c32bf745e4c8620409fdc238 Signed-off-by: Alex Tuyls <alt-odoo@users.noreply.github.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import odoo.modules
|
||||
from odoo import api, models, fields
|
||||
from odoo.tools import ustr, posix_to_ldml, pycompat
|
||||
from odoo.tools import html_escape as escape
|
||||
from odoo.tools.misc import get_lang
|
||||
from odoo.addons.base.models import ir_qweb
|
||||
|
||||
REMOTE_CONNECTION_TIMEOUT = 2.5
|
||||
@@ -211,7 +212,7 @@ class Date(models.AbstractModel):
|
||||
attrs['data-oe-type'] = 'datetime'
|
||||
return attrs
|
||||
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang)
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang) or get_lang(self.env)
|
||||
locale = babel.Locale.parse(lg.code)
|
||||
babel_format = value_format = posix_to_ldml(lg.date_format, locale=locale)
|
||||
|
||||
@@ -228,7 +229,7 @@ class Date(models.AbstractModel):
|
||||
if not value:
|
||||
return False
|
||||
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang)
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang) or get_lang(self.env)
|
||||
date = datetime.strptime(value, lg.date_format)
|
||||
return fields.Date.to_string(date)
|
||||
|
||||
@@ -245,7 +246,7 @@ class DateTime(models.AbstractModel):
|
||||
if options.get('inherit_branding'):
|
||||
value = record[field_name]
|
||||
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang)
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang) or get_lang(self.env)
|
||||
locale = babel.Locale.parse(lg.code)
|
||||
babel_format = value_format = posix_to_ldml('%s %s' % (lg.date_format, lg.time_format), locale=locale)
|
||||
tz = record.env.context.get('tz') or self.env.user.tz
|
||||
@@ -271,7 +272,7 @@ class DateTime(models.AbstractModel):
|
||||
return False
|
||||
|
||||
# parse from string to datetime
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang)
|
||||
lg = self.env['res.lang']._lang_get(self.env.user.lang) or get_lang(self.env)
|
||||
dt = datetime.strptime(value, '%s %s' % (lg.date_format, lg.time_format))
|
||||
|
||||
# convert back from user's timezone to UTC
|
||||
|
||||
Reference in New Issue
Block a user