[FIX] web: ListView: do not crash on aggregated date fields
Have a model with date(time) field with a group_operator (e.g. "min"). Open a grouped list view of that model, containing that field. Before this commit it crashed, because the aggregated value of the date field, for each group, wasn't parsed (it was still a string), whereas the code trying to display it expected a luxon instance. We could have easily fixed the issue by parsing the aggregated values for date fields. However, it wasn't supported in legacy views, and it would raise questions. For instance, views aren't designed with this in mind (aggregated fields are often positioned to the right, to leave enough space for the group's title). For that reason, this commit simply restores the legacy behavior, that is, we only consider aggregated values for "integer", "float" and "monetary" fields. The issue occurred in the Journal Items list view. closes odoo/odoo#100595 Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
@@ -30,6 +30,7 @@ const preloadedDataRegistry = registry.category("preloadedData");
|
||||
|
||||
const { CREATE, UPDATE, DELETE, FORGET, LINK_TO, DELETE_ALL, REPLACE_WITH } = x2ManyCommands;
|
||||
const QUICK_CREATE_FIELD_TYPES = ["char", "boolean", "many2one", "selection"];
|
||||
const AGGREGATABLE_FIELD_TYPES = ["float", "integer", "monetary"]; // types that can be aggregated in grouped views
|
||||
const DEFAULT_HANDLE_FIELD = "sequence";
|
||||
const DEFAULT_QUICK_CREATE_FIELDS = {
|
||||
display_name: { string: "Display name", type: "char" },
|
||||
@@ -2411,7 +2412,9 @@ export class DynamicGroupList extends DynamicList {
|
||||
default: {
|
||||
// other optional aggregated fields
|
||||
if (key in this.fields) {
|
||||
groupParams.aggregates[key] = value;
|
||||
if (AGGREGATABLE_FIELD_TYPES.includes(this.fields[key].type)) {
|
||||
groupParams.aggregates[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2777,6 +2777,36 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_list_number")), cellVals);
|
||||
});
|
||||
|
||||
QUnit.test("date field aggregates in grouped lists", async function (assert) {
|
||||
// this test simulates a scenario where a date field has a group_operator
|
||||
// and the web_read_group thus return a value for that field for each group
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "foo",
|
||||
serverData,
|
||||
groupBy: ["m2o"],
|
||||
arch: `
|
||||
<tree>
|
||||
<field name="foo"/>
|
||||
<field name="date"/>
|
||||
</tree>`,
|
||||
async mockRPC(route, args, performRPC) {
|
||||
if (args.method === "web_read_group") {
|
||||
const res = await performRPC(...arguments);
|
||||
res.groups[0].date = "2021-03-15";
|
||||
res.groups[1].date = "2021-02-11";
|
||||
return res;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsN(target, ".o_group_header", 2);
|
||||
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_group_header")), [
|
||||
`Value 1 (3) `,
|
||||
`Value 2 (1) `,
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"hide aggregated value in grouped lists when no data provided by RPC call",
|
||||
async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user