summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Grazioso (agr-odoo) <agr@odoo.com>2019-09-17 11:48:11 +0000
committerAndrea Grazioso (agr-odoo) <agr@odoo.com>2019-09-20 05:37:56 +0000
commit3ee3f7d497328dd09b0bc07349872f1b03bbe8e5 (patch)
treef554a5ab85e70aaeaad766829bf4946bfb79676d
parent151666b79d1fab2666b5078bc6b81a7fba12c53a (diff)
[FIX] web: digits option not applied in list view
From the settings activate: - Multiple Sales Prices per Product -- Prices computed from formulas - Discounts Create a pricelist with discount policy "Show public price & discount to the customer", set the price calculation formula: - Rounding: 10 - Price discount: 10% Modify the sale order xml list view adding 'digits="[3, 2]"' to the discount shown in the sale order line. Create a sale order with such pricelist and on the so line put a product with quantity 1 and sale price 4190 (VAT 19% included in the price). The discount will not display the requested number of decimal digits (2) in list view, but it will when editing the field. The cell formatting is done calling the appropriate function (formatFloat), which search the digits option from the 'options' parameter or from the field definition. The latter stores the default digits coming from the DecimalAccuracy settings, which, as side effect, alter the behavior of the discount calculation. https://www.odoo.com/web#view_type=form&model=project.task&id=2069939&active_id=2069939 When passing into edit mode the field is created as widget, parsing its options which have 'digits', instead when coming back in list mode it is "just a float field" rendered directly from the list_renderer which no options, so the formatFloat will look at the field definition https://github.com/odoo/odoo/blob/12.0/addons/web/static/src/js/fields/field_utils.js#L172 Adding the correct parameter to the dictionary passed to formatFloat during the list rendering is a possible solution, because it is the "closest" point in which parsing the parameter is possible without touching higher level code or forcing the creation of a widget (adding widget='float' as xml parameter). closes odoo/odoo#37167 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js1
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js36
2 files changed, 37 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js
index 1fc6b7006b9..7ed24ad7fb4 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -363,6 +363,7 @@ var ListRenderer = BasicRenderer.extend({
data: record.data,
escape: true,
isPassword: 'password' in node.attrs,
+ digits: node.attrs.digits ? JSON.parse(node.attrs.digits) : undefined,
});
this._handleAttributes($td, node);
var title = field.type !== 'boolean' ? formattedValue : '';
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index 37f7b31fe12..94d7a5097d3 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -529,6 +529,42 @@ QUnit.module('basic_fields', {
form.destroy();
});
+ QUnit.test('float field in list view no widget', async function (assert) {
+ assert.expect(5);
+
+ var form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<field name="qux" digits="[5,3]"/>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 2,
+ });
+
+ assert.doesNotHaveClass(form.$('.o_field_widget'), 'o_field_empty',
+ 'Float field should be considered set for value 0.');
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '0.000',
+ 'The value should be displayed properly.');
+
+ await testUtils.form.clickEdit(form);
+ assert.strictEqual(form.$('input[name=qux]').val(), '0.000',
+ 'The value should be rendered with correct precision.');
+
+ await testUtils.fields.editInput(form.$('input[name=qux]'), '108.2458938598598');
+ assert.strictEqual(form.$('input[name=qux]').val(), '108.2458938598598',
+ 'The value should not be formated yet.');
+
+ await testUtils.fields.editInput(form.$('input[name=qux]'), '18.8958938598598');
+ await testUtils.form.clickSave(form);
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '18.896',
+ 'The new value should be rounded properly.');
+
+ form.destroy();
+ });
+
QUnit.test('float field in form view', async function (assert) {
assert.expect(5);