From f360965dc2f0c81219b79da2e96d55482a5eaa8c Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Tue, 27 Sep 2022 13:14:37 +0000 Subject: [PATCH] [FIX] web: group a list view with a date field Before this commit, in a grouped list view, if a date field is between two fields with an operator_group then the view crashes. Why is this? The view will try to format the aggregated date value but the date does not have one. Solution: Use the value false if there is no aggregated value for a field. closes odoo/odoo#101573 X-original-commit: c9485ea3dd377f486fb7543fc1092175006fc987 Signed-off-by: Aaron Bohy (aab) --- .../static/src/views/list/list_renderer.js | 3 ++ .../web/static/tests/views/list_view_tests.js | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index 7442856bdac..de0bc8d06b7 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -545,6 +545,9 @@ export class ListRenderer extends Component { const { widget, rawAttrs } = column; const fieldType = this.props.list.fields[column.name].type; const aggregateValue = group.aggregates[column.name]; + if (!(column.name in group.aggregates)) { + return ""; + } const formatter = formatters.get(widget, false) || formatters.get(fieldType, false); const formatOptions = { digits: rawAttrs.digits ? JSON.parse(rawAttrs.digits) : undefined, diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 3c1aa37db7c..63c705a6af8 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -1281,6 +1281,39 @@ QUnit.module("Views", (hooks) => { assert.containsNone(target.querySelector(".o_group_header"), ".o_list_number"); }); + QUnit.test( + "basic grouped list rendering with a date field between two fields with a group_operator", + async function (assert) { + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: ` + + + + + `, + groupBy: ["bar"], + }); + + assert.containsN(target, "thead th", 4); // record selector + Foo + Int + Date + Int + assert.containsOnce(target, "thead th.o_list_record_selector"); + assert.deepEqual(getNodesTextContent(target.querySelectorAll("thead th")), [ + "", + "int_field", + "Some Date", + "int_field", + ]); + assert.containsN(target, "tr.o_group_header", 2); + assert.containsN(target, "th.o_group_name", 2); + assert.deepEqual( + getNodesTextContent(target.querySelector(".o_group_header").querySelectorAll("td")), + ["-4", "", "-4"] + ); + } + ); + QUnit.test("basic grouped list rendering 1 col without selector", async function (assert) { await makeView({ type: "list",