Fix for empty lang in format_lang:
- Use a lambda to wrap format_lang and provide cursor and user - Call the new default_code on ir.lang instead of using static 'en_US'
This commit is contained in:
1 parent
768e98e26a
commit
84f6557c93
2 files changed
+11
-5
No files matched your search
@@ -70,6 +70,9 @@ class Lang(ModelSQL, ModelView, Cacheable):
|
||||
del record['code']
|
||||
return res
|
||||
|
||||
def default_code(self, cursor, user, context=None):
|
||||
return 'en_US'
|
||||
|
||||
def default_active(self, cursor, user, context=None):
|
||||
return 1
|
||||
|
||||
|
||||
@@ -125,7 +125,8 @@ class Report(object):
|
||||
localcontext['datas'] = datas
|
||||
localcontext['user'] = self.pool.get('res.user').\
|
||||
browse(cursor, user, user)
|
||||
localcontext['formatLang'] = self.format_lang
|
||||
localcontext['formatLang'] = lambda *args, **kargs: \
|
||||
self.format_lang(*((cursor, user) + args), **kargs)
|
||||
localcontext['decodestring'] = decodestring
|
||||
localcontext['StringIO'] = StringIO.StringIO
|
||||
localcontext['time'] = time
|
||||
@@ -276,15 +277,17 @@ class Report(object):
|
||||
return res
|
||||
return None
|
||||
|
||||
def format_lang(self, value, lang, digits=2, grouping=True, monetary=False,
|
||||
date=False, currency=None):
|
||||
def format_lang(self, cursor, user, value, lang, digits=2, grouping=True,
|
||||
monetary=False, date=False, currency=None):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
|
||||
if date:
|
||||
if lang:
|
||||
locale_format = lang.date
|
||||
code = lang.code
|
||||
else:
|
||||
locale_format = lang_obj.default_date(None, None)
|
||||
locale_format = lang_obj.default_date(cursor, user)
|
||||
code = lang_obj.default_code(cursor, user)
|
||||
if not isinstance(value, time.struct_time):
|
||||
# assume string, parse it
|
||||
if len(str(value)) == 10:
|
||||
@@ -299,7 +302,7 @@ class Report(object):
|
||||
date = mx.DateTime.strptime(str(value), string_pattern)
|
||||
else:
|
||||
date = mx.DateTime.DateTime(*(value.timetuple()[:6]))
|
||||
return lang_obj.strftime(date.tuple(), lang.code, locale_format)
|
||||
return lang_obj.strftime(date.tuple(), code, locale_format)
|
||||
if currency:
|
||||
return lang_obj.currency(lang, value, currency, grouping=grouping)
|
||||
return lang_obj.format(lang, '%.' + str(digits) + 'f', value,
|
||||
|
||||
Reference in new issue
Block a user