[IMP] Removed 1 SQL query for each t-field monetary or float

bzr revid: fp@tinyerp.com-20131203211903-p5uo3shhon8i4umw
This commit is contained in:
Fabien Pinckaers
2013-12-03 22:19:03 +01:00
parent 73c943d9b3
commit dc35f14d32
2 changed files with 15 additions and 7 deletions
+6 -5
View File
@@ -608,10 +608,10 @@ class FloatConverter(osv.AbstractModel):
precision = self.precision(cr, uid, column, options=options, context=context)
fmt = '%f' if precision is None else '%.{precision}f'
lang = self.user_lang(cr, uid, context)
lang_code = context.get('lang') or 'en_US'
lang = self.pool['res.lang']
formatted = lang.format(cr, uid, [lang_code], fmt.format(precision=precision), value, grouping=True)
formatted = lang.format(fmt.format(precision=precision),
value, grouping=True)
# %f does not strip trailing zeroes. %g does but its precision causes
# it to switch to scientific notation starting at a million *and* to
# strip decimals. So use %f and if no precision was specified manually
@@ -767,8 +767,9 @@ class MonetaryConverter(osv.AbstractModel):
precision = int(round(math.log10(display.rounding)))
fmt = "%.{0}f".format(-precision if precision < 0 else 0)
lang = self.user_lang(cr, uid, context=context)
formatted_amount = lang.format(
lang_code = context.get('lang') or 'en_US'
lang = self.pool['res.lang']
formatted_amount = lang.format(cr, uid, [lang_code],
fmt, Currency.round(cr, uid, display, record[field_name]),
grouping=True, monetary=True)
+9 -2
View File
@@ -162,9 +162,13 @@ class lang(osv.osv):
]
@tools.ormcache(skiparg=3)
def _lang_data_get(self, cr, uid, lang_id, monetary=False):
def _lang_data_get(self, cr, uid, lang, monetary=False):
if type(lang) in (str, unicode):
lang = self.search(cr, uid, [('code', '=', lang)]) or \
self.search(cr, uid, [('code', '=', 'en_US')])
lang = lang[0]
conv = localeconv()
lang_obj = self.browse(cr, uid, lang_id)
lang_obj = self.browse(cr, uid, lang)
thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
decimal_point = lang_obj.decimal_point
grouping = lang_obj.grouping
@@ -192,6 +196,9 @@ class lang(osv.osv):
trans_obj.unlink(cr, uid, trans_ids, context=context)
return super(lang, self).unlink(cr, uid, ids, context=context)
#
# IDS: can be a list of IDS or a list of XML_IDS
#
def format(self, cr, uid, ids, percent, value, grouping=False, monetary=False, context=None):
""" Format() will return the language-specific output for float values"""
if percent[0] != '%':