[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) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2022-09-29 13:23:09 +02:00
parent a8b46857ea
commit f360965dc2
2 changed files with 36 additions and 0 deletions
@@ -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,
@@ -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: `
<tree>
<field name="int_field"/>
<field name="date"/>
<field name="int_field"/>
</tree>`,
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",