[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>
This commit is contained in:
@@ -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 : '';
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user