[FIX] web: digits option for aggregate is taken into account
If you have a currency with 3 decimals, when you show a list view
grouped, you might have result like:
[group partner 1 : amount : 4.4€]
- amount : 1.11€
- amount : 3.33€
which is a little odd, it is not that odd since the groupings are an
approximation (eg. you could have a line in EUR and a line in USD and
the grouping value would be the sum of both line).
But there is no way to specify another precision, and since this is a
grouping it could be of line of different currencies so we can't use the
lines currency to decide.
With this changeset, having for example:
<field name="amount" digits="[69,3]"/>
with `digits` attribute is taken into account for the aggregate value
and it would be displayed with 3 decimals.
Without the fix, the added test fails with:
aggregates monetary use digits attribute if available
Expected: "2000.000", Result: "2000.00"
opw-2195042
closes #45545
closes odoo/odoo#46094
X-original-commit: 4dd293c71851d0c6e9ffe09402cf54cfe889f402
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
@@ -352,7 +352,10 @@ var ListRenderer = BasicRenderer.extend({
|
||||
if (!formatFunc) {
|
||||
formatFunc = field_utils.format[field.type];
|
||||
}
|
||||
var formattedValue = formatFunc(value, field, { escape: true });
|
||||
var formattedValue = formatFunc(value, field, {
|
||||
escape: true,
|
||||
digits: column.attrs.digits ? JSON.parse(column.attrs.digits) : undefined,
|
||||
});
|
||||
$cell.addClass('o_list_number').attr('title', help).html(formattedValue);
|
||||
}
|
||||
return $cell;
|
||||
|
||||
@@ -1412,6 +1412,26 @@ QUnit.module('Views', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('aggregates digits can be set with digits field attribute', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<tree>' +
|
||||
'<field name="amount" widget="monetary" sum="Sum" digits="[69,3]"/>' +
|
||||
'</tree>',
|
||||
});
|
||||
|
||||
assert.strictEqual(list.$('.o_data_row td:nth(1)').text(), '1200.00',
|
||||
"field should still be formatted based on currency");
|
||||
assert.strictEqual(list.$('tfoot td:nth(1)').text(), '2000.000',
|
||||
"aggregates monetary use digits attribute if available");
|
||||
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('groups can be sorted on aggregates', async function (assert) {
|
||||
assert.expect(10);
|
||||
var list = await createView({
|
||||
|
||||
Reference in New Issue
Block a user