[FIX] support 'thousands' separator for integers
lp bug: https://launchpad.net/bugs/886471 fixed bzr revid: xmo@openerp.com-20111114154510-r6bdi22cyygh72ak
This commit is contained in:
parent
4aafc01a3c
commit
42c7cb86d9
|
@ -993,7 +993,7 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.we
|
|||
this.parameters = {"direction": 'ltr',
|
||||
"date_format": '%m/%d/%Y',
|
||||
"time_format": '%H:%M:%S',
|
||||
"grouping": "[]",
|
||||
"grouping": [],
|
||||
"decimal_point": ".",
|
||||
"thousands_sep": ","};
|
||||
},
|
||||
|
@ -1009,6 +1009,8 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.we
|
|||
});
|
||||
if (translation_bundle.lang_parameters) {
|
||||
this.parameters = translation_bundle.lang_parameters;
|
||||
this.parameters.grouping = py.eval(
|
||||
this.parameters.grouping).toJSON();
|
||||
}
|
||||
},
|
||||
add_module_translation: function(mod) {
|
||||
|
|
|
@ -69,13 +69,15 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) {
|
|||
case -Infinity:
|
||||
return value_if_empty === undefined ? '' : value_if_empty;
|
||||
}
|
||||
var l10n = _t.database.parameters;
|
||||
switch (descriptor.widget || descriptor.type) {
|
||||
case 'integer':
|
||||
return _.sprintf('%d', value);
|
||||
return openerp.web.intersperse(
|
||||
_.sprintf('%d', value), l10n.grouping, l10n.thousands_sep);
|
||||
case 'float':
|
||||
var precision = descriptor.digits ? descriptor.digits[1] : 2;
|
||||
return _.sprintf('%.' + precision + 'f', value)
|
||||
.replace('.', openerp.web._t.database.parameters.decimal_point);
|
||||
.replace('.', l10n.decimal_point);
|
||||
case 'float_time':
|
||||
return _.sprintf("%02d:%02d",
|
||||
Math.floor(value),
|
||||
|
@ -91,16 +93,16 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) {
|
|||
if (typeof(value) == "string")
|
||||
value = openerp.web.auto_str_to_date(value);
|
||||
|
||||
return value.format(_t.database.parameters.date_format
|
||||
+ ' ' + _t.database.parameters.time_format);
|
||||
return value.format(l10n.date_format
|
||||
+ ' ' + l10n.time_format);
|
||||
case 'date':
|
||||
if (typeof(value) == "string")
|
||||
value = openerp.web.auto_str_to_date(value);
|
||||
return value.format(_t.database.parameters.date_format);
|
||||
return value.format(l10n.date_format);
|
||||
case 'time':
|
||||
if (typeof(value) == "string")
|
||||
value = openerp.web.auto_str_to_date(value);
|
||||
return value.format(_t.database.parameters.time_format);
|
||||
return value.format(l10n.time_format);
|
||||
case 'selection':
|
||||
// Each choice is [value, label]
|
||||
var result = _(descriptor.selection).detect(function (choice) {
|
||||
|
|
|
@ -95,4 +95,15 @@ $(document).ready(function () {
|
|||
equal(g("12345678", [2, 0, 0], '.'), '12.34.56.78');
|
||||
equal(g("12345678", [2, 0, -1], '.'), '12.34.56.78');
|
||||
});
|
||||
test('format_integer', function () {
|
||||
openerp.web._t.database.parameters.grouping = [3, 3, 3, 3];
|
||||
equal(openerp.web.format_value(1000000, {type: 'integer'}),
|
||||
'1,000,000');
|
||||
openerp.web._t.database.parameters.grouping = [3, 2, -1];
|
||||
equal(openerp.web.format_value(106500, {type: 'integer'}),
|
||||
'1,06,500');
|
||||
openerp.web._t.database.parameters.grouping = [1, 2, -1];
|
||||
equal(openerp.web.format_value(106500, {type: 'integer'}),
|
||||
'106,50,0');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
<script src="/web/static/lib/qweb/qweb2.js"></script>
|
||||
|
||||
<script src="/web/static/lib/py.parse/lib/py.js"></script>
|
||||
|
||||
<script src="/web/static/src/js/boot.js"></script>
|
||||
<script src="/web/static/src/js/core.js"></script>
|
||||
<script src="/web/static/src/js/dates.js"></script>
|
||||
|
|
Loading…
Reference in New Issue