summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorlen-odoo <len@odoo.com>2018-07-11 18:20:18 +0200
committerlen-odoo <35492570+len-odoo@users.noreply.github.com>2018-07-19 13:19:09 +0200
commitbc12428e174dcba94d86e855cbeba0e77da9b747 (patch)
tree37dd946d90fa86ca73b790ef6eca615c235c15e6 /addons/web/static
parent487873f170d50ec6f6f625dbacc85680bd32e7bf (diff)
[FIX] web: format value of statinfo widget
The value of the statinfo widget is rendered by the qweb after a t-esc. Say if the python rounding returned 14.0000000001 (supposed to be a two digits precision number through the magic of floats) then the statinfo widget would print it as-is. We now format the value at assignation. opw 1865426
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js2
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js34
2 files changed, 35 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 4e083d3f0c8..ee52f4a27e5 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -1759,7 +1759,7 @@ var StatInfo = AbstractField.extend({
*/
_render: function () {
var options = {
- value: this.value || 0,
+ value: this._formatValue(this.value || 0),
};
if (! this.attrs.nolabel) {
if (this.nodeOptions.label_field && this.recordData[this.nodeOptions.label_field]) {
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index 7f1742b3041..f2ab670f097 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -4001,6 +4001,40 @@ QUnit.module('basic_fields', {
QUnit.module('StatInfo');
+ QUnit.test('statinfo widget formats decimal precision', function (assert) {
+ // sometimes the round method can return numbers such as 14.000001
+ // when asked to round a number to 2 decimals, as such is the behaviour of floats.
+ // we check that even in that eventuality, only two decimals are displayed
+ assert.expect(2);
+
+ this.data.partner.fields.monetary = {string: "Monetary", type: 'monetary'};
+ this.data.partner.records[0].monetary = 9.999999;
+ this.data.partner.records[0].currency_id = 1;
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<button class="oe_stat_button" name="items" icon="fa-gear">' +
+ '<field name="qux" widget="statinfo"/>' +
+ '</button>' +
+ '<button class="oe_stat_button" name="money" icon="fa-money">' +
+ '<field name="monetary" widget="statinfo"/>' +
+ '</button>' +
+ '</form>',
+ res_id: 1,
+ });
+
+ // formatFloat renders according to this.field.digits
+ assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').eq(0).text(),
+ '0.4', "Default precision should be [16,1]");
+ assert.strictEqual(form.$('.oe_stat_button .o_field_widget.o_stat_info .o_stat_value').eq(1).text(),
+ '10.00', "Currency decimal precision should be 2");
+
+ form.destroy();
+ });
+
QUnit.test('statinfo widget in form view', function (assert) {
assert.expect(9);