~openerp-dev/openobject-server/trunk-missing-default-values-pza

« back to all changes in this revision

Viewing changes to openerp/addons/base/res/res_lang.py

  • Committer: Antony Lesuisse
  • Date: 2014-01-31 00:52:07 UTC
  • mfrom: (4854.4.369 trunk-website-al)
  • mto: This revision was merged to the branch mainline in revision 5025.
  • Revision ID: al@openerp.com-20140131005207-mn7t6tar8cywe9hz
[MERGE] trunk-website-al

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
    ]
163
163
 
164
164
    @tools.ormcache(skiparg=3)
165
 
    def _lang_data_get(self, cr, uid, lang_id, monetary=False):
 
165
    def _lang_data_get(self, cr, uid, lang, monetary=False):
 
166
        if type(lang) in (str, unicode):
 
167
            lang = self.search(cr, uid, [('code', '=', lang)]) or \
 
168
                self.search(cr, uid, [('code', '=', 'en_US')])
 
169
            lang = lang[0]
166
170
        conv = localeconv()
167
 
        lang_obj = self.browse(cr, uid, lang_id)
 
171
        lang_obj = self.browse(cr, uid, lang)
168
172
        thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
169
173
        decimal_point = lang_obj.decimal_point
170
174
        grouping = lang_obj.grouping
192
196
            trans_obj.unlink(cr, uid, trans_ids, context=context)
193
197
        return super(lang, self).unlink(cr, uid, ids, context=context)
194
198
 
 
199
    #
 
200
    # IDS: can be a list of IDS or a list of XML_IDS
 
201
    #
195
202
    def format(self, cr, uid, ids, percent, value, grouping=False, monetary=False, context=None):
196
203
        """ Format() will return the language-specific output for float values"""
197
 
 
198
204
        if percent[0] != '%':
199
205
            raise ValueError("format() must be given exactly one %char format specifier")
200
206
 
201
 
        lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0], monetary)
202
 
        eval_lang_grouping = eval(lang_grouping)
203
 
 
204
207
        formatted = percent % value
 
208
 
205
209
        # floats and decimal ints need special action!
206
 
        if percent[-1] in 'eEfFgG':
207
 
            seps = 0
208
 
            parts = formatted.split('.')
209
 
 
210
 
            if grouping:
211
 
                parts[0], seps = intersperse(parts[0], eval_lang_grouping, thousands_sep)
212
 
 
213
 
            formatted = decimal_point.join(parts)
214
 
            while seps:
215
 
                sp = formatted.find(' ')
216
 
                if sp == -1: break
217
 
                formatted = formatted[:sp] + formatted[sp+1:]
218
 
                seps -= 1
219
 
        elif percent[-1] in 'diu':
220
 
            if grouping:
 
210
        if grouping:
 
211
            lang_grouping, thousands_sep, decimal_point = \
 
212
                self._lang_data_get(cr, uid, ids[0], monetary)
 
213
            eval_lang_grouping = eval(lang_grouping)
 
214
 
 
215
            if percent[-1] in 'eEfFgG':
 
216
                parts = formatted.split('.')
 
217
                parts[0], _ = intersperse(parts[0], eval_lang_grouping, thousands_sep)
 
218
 
 
219
                formatted = decimal_point.join(parts)
 
220
 
 
221
            elif percent[-1] in 'diu':
221
222
                formatted = intersperse(formatted, eval_lang_grouping, thousands_sep)[0]
222
223
 
223
224
        return formatted