From 31c975ae94101df5202bee512e7ba014433d105e Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 14 Sep 2022 13:26:35 +0000 Subject: [PATCH] [FIX] web: ListView: correctly format group aggregates Before this commit, if a grouped list view contained an aggregatable field (e.g. a float field) with a widget for which there's no associated formatter (e.g. progressbar), the aggregate value was left unformatted. It was for instance the case in the "My tasks" list view, with the field "progress". With this commit, the value is formatted according to the field type, as expected. Part-of: odoo/odoo#100356 --- .../static/src/views/list/list_renderer.js | 5 ++-- .../web/static/tests/views/list_view_tests.js | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index 03348a23965..e43817143c0 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -544,9 +544,10 @@ export class ListRenderer extends Component { } formatAggregateValue(group, column) { - const { widget, type, rawAttrs } = column; + const { widget, rawAttrs } = column; + const fieldType = this.props.list.fields[column.name].type; const aggregateValue = group.aggregates[column.name]; - const formatter = formatters.get(widget, false) || formatters.get(type, false); + const formatter = formatters.get(widget, false) || formatters.get(fieldType, false); const formatOptions = { digits: rawAttrs.digits ? JSON.parse(rawAttrs.digits) : undefined, escape: true, diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 89193d519b9..9a6e4dea8fa 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -56,11 +56,13 @@ import { import { createWebClient, doAction, loadState } from "../webclient/helpers"; import { makeView, setupViewRegistries } from "./helpers"; import { getNextTabableElement } from "@web/core/utils/ui"; +import { FloatField } from "@web/views/fields/float/float_field"; import { TextField } from "@web/views/fields/text/text_field"; import { DynamicRecordList } from "@web/views/relational_model"; const { Component, onWillStart, xml } = owl; +const fieldRegistry = registry.category("fields"); const serviceRegistry = registry.category("services"); let serverData; @@ -2713,6 +2715,29 @@ QUnit.module("Views", (hooks) => { ); }); + QUnit.test("aggregates are formatted correctly in grouped lists", async function (assert) { + // in this scenario, there is a widget on an aggregated field, and this widget has no + // associated formatter, so we fallback on the formatter corresponding to the field type + fieldRegistry.add("my_float", FloatField); + serverData.models.foo.records[0].qux = 5.1654846456; + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: ` + + + + `, + groupBy: ["int_field"], + }); + + assert.deepEqual( + getNodesTextContent(target.querySelectorAll(".o_group_header .o_list_number")), + ["9.00", "13.00", "5.17", "-3.00"] + ); + }); + QUnit.test("aggregates in grouped lists with buttons", async function (assert) { await makeView({ type: "list", @@ -2728,7 +2753,7 @@ QUnit.module("Views", (hooks) => { `, }); - const cellVals = ["23", "6.4", "9", "13", "32", "19.40"]; + const cellVals = ["23", "6.40", "9", "13.00", "32", "19.40"]; assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_list_number")), cellVals); });