[REF] simplification of res.lang format
authorXavier Morel <xmo@openerp.com>
Mon, 21 Oct 2013 11:14:57 +0000 (13:14 +0200)
committerXavier Morel <xmo@openerp.com>
Mon, 21 Oct 2013 11:14:57 +0000 (13:14 +0200)
bzr revid: xmo@openerp.com-20131021111457-k9rgt5ojnk9doqh9

openerp/addons/base/res/res_lang.py

index 160e86f..d33ce0b 100644 (file)
@@ -194,30 +194,24 @@ class lang(osv.osv):
 
     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] != '%':
             raise ValueError("format() must be given exactly one %char format specifier")
 
-        lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0], monetary)
-        eval_lang_grouping = eval(lang_grouping)
-
         formatted = percent % value
+
         # floats and decimal ints need special action!
-        if percent[-1] in 'eEfFgG':
-            seps = 0
-            parts = formatted.split('.')
-
-            if grouping:
-                parts[0], seps = intersperse(parts[0], eval_lang_grouping, thousands_sep)
-
-            formatted = decimal_point.join(parts)
-            while seps:
-                sp = formatted.find(' ')
-                if sp == -1: break
-                formatted = formatted[:sp] + formatted[sp+1:]
-                seps -= 1
-        elif percent[-1] in 'diu':
-            if grouping:
+        if grouping:
+            lang_grouping, thousands_sep, decimal_point = \
+                self._lang_data_get(cr, uid, ids[0], monetary)
+            eval_lang_grouping = eval(lang_grouping)
+
+            if percent[-1] in 'eEfFgG':
+                parts = formatted.split('.')
+                parts[0], _ = intersperse(parts[0], eval_lang_grouping, thousands_sep)
+
+                formatted = decimal_point.join(parts)
+
+            elif percent[-1] in 'diu':
                 formatted = intersperse(formatted, eval_lang_grouping, thousands_sep)[0]
 
         return formatted