From 42c7cb86d94a9b2b655f114a2477b82b1c2a669b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 14 Nov 2011 16:45:10 +0100 Subject: [PATCH] [FIX] support 'thousands' separator for integers lp bug: https://launchpad.net/bugs/886471 fixed bzr revid: xmo@openerp.com-20111114154510-r6bdi22cyygh72ak --- addons/web/static/src/js/core.js | 4 +++- addons/web/static/src/js/formats.js | 14 ++++++++------ addons/web/static/test/formats.js | 11 +++++++++++ addons/web/static/test/test.html | 2 ++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 0b49e1cc52d..369e1191665 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -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) { diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index 62a97602487..385b1925454 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -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) { diff --git a/addons/web/static/test/formats.js b/addons/web/static/test/formats.js index 418d2c0101e..189a1bb4475 100644 --- a/addons/web/static/test/formats.js +++ b/addons/web/static/test/formats.js @@ -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'); + }); }); diff --git a/addons/web/static/test/test.html b/addons/web/static/test/test.html index f6248e705c0..d182ce18707 100644 --- a/addons/web/static/test/test.html +++ b/addons/web/static/test/test.html @@ -23,6 +23,8 @@ + +