[FIX] web: kanban grouped by many2one: keep false group open

In a kanban (or list actually) view grouped by a many2one field,
the "false" group is folded by default. Before this commit, if the
user opened it and then reloaded the view (e.g. by applying a
filter in the search view), the group was folded again. With this
commit, the group remains open if the user manually opened it.

closes odoo/odoo#133305

Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
This commit is contained in:
Aaron Bohy
2023-08-29 07:48:13 +00:00
parent 049fe6f9ed
commit 1da9684ddf
2 changed files with 49 additions and 4 deletions
@@ -410,7 +410,7 @@ export class RelationalModel extends Model {
groupData[config.groupBy[0]],
group.range
);
group.rawValue = groupData[config.groupBy];
group.rawValue = groupData[config.groupBy[0]];
group.displayName = getDisplayNameFromGroupData(
groupByField,
groupData[config.groupBy[0]]
@@ -429,6 +429,10 @@ export class RelationalModel extends Model {
groupBy,
},
};
if (isRelational(config.fields[firstGroupByName]) && !group.value) {
// fold the "unset" group by default when grouped by many2one
config.groups[group.value].isFolded = true;
}
if (groupRecordConfig) {
config.groups[group.value].record = {
...groupRecordConfig,
@@ -464,9 +468,6 @@ export class RelationalModel extends Model {
} else {
group.records = [];
}
if (isRelational(config.fields[firstGroupByName]) && !group.value) {
groupConfig.isFolded = true;
}
if (!groupConfig.isFolded) {
nbOpenGroups++;
if (nbOpenGroups > this.constructor.MAX_NUMBER_OPENED_GROUPS) {
@@ -1738,6 +1738,50 @@ QUnit.module("Views", (hooks) => {
assert.containsN(target, ".thisisdeletable", 4, "records should be deletable");
});
QUnit.test("kanban grouped by many2one: false column is folded by default", async (assert) => {
serverData.models.partner.records[0].product_id = false;
const kanban = await makeView({
type: "kanban",
resModel: "partner",
serverData,
arch: `
<kanban>
<templates>
<t t-name="kanban-box">
<div><field name="foo"/></div>
</t>
</templates>
</kanban>`,
groupBy: ["product_id"],
});
assert.containsN(target, ".o_kanban_group", 3);
assert.containsOnce(target, ".o_column_folded");
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_kanban_header")), [
"None1",
"hello",
"xmo",
]);
await click(target.querySelector(".o_kanban_header"));
assert.containsNone(target, ".o_column_folded");
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_kanban_header")), [
"None",
"hello",
"xmo",
]);
// reload -> None column should remain open
await reload(kanban, { groupBy: ["product_id"] });
assert.containsNone(target, ".o_column_folded");
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_kanban_header")), [
"None",
"hello",
"xmo",
]);
});
QUnit.test("quick created records in grouped kanban are on displayed top", async (assert) => {
await makeView({
type: "kanban",