[FIX] web: RelationalModel: find previous group with date
When a list or kanban view is grouped, at each reload, we try to match the fetched groups with the previously created Group datapoints, such that we can restore/keep the state of each group (for instance, the fact that it is folded, the limit of the inner list...). Before this commit, this didn't work when the view was grouped by a date or datetime field, because in those cases, the value of the group was a luxon instance, and strict equality between two different luxon instances, even if they represent the same value, is always false. This commit fixes the issue. Issue reported in the feedback pad after migrating odoo.com to 16.0. closes odoo/odoo#110046 X-original-commit: 80fa8f187939d78ea644a49ec17c112bcc97b32b Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -2542,9 +2542,15 @@ export class DynamicGroupList extends DynamicList {
|
||||
}
|
||||
}
|
||||
}
|
||||
const previousGroup = this.groups.find(
|
||||
(g) => !g.deleted && g.value === groupParams.value
|
||||
);
|
||||
const groupValue = groupParams.__rawValue;
|
||||
const previousGroup = this.groups.find((g) => {
|
||||
if (g.deleted) {
|
||||
return false;
|
||||
}
|
||||
return Array.isArray(g.__rawValue) && Array.isArray(groupValue)
|
||||
? g.__rawValue[0] === groupValue[0]
|
||||
: g.__rawValue === groupValue;
|
||||
});
|
||||
const state = previousGroup ? previousGroup.exportState() : {};
|
||||
return [groupParams, state];
|
||||
});
|
||||
|
||||
@@ -10668,6 +10668,59 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.containsN(target, ".o_kanban_record", 2);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"folded groups are kept when leaving and coming back (grouped by date)",
|
||||
async (assert) => {
|
||||
serverData.models.partner.fields.date.default = "2022-10-10";
|
||||
serverData.models.partner.records[0].date = "2022-05-10";
|
||||
serverData.views = {
|
||||
"partner,false,kanban": `
|
||||
<kanban>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_kanban_global_click">
|
||||
<field name="int_field"/>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>`,
|
||||
"partner,false,search": "<search/>",
|
||||
"partner,false,form": "<form/>",
|
||||
};
|
||||
const webClient = await createWebClient({ serverData });
|
||||
await doAction(webClient, {
|
||||
name: "Partners",
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [
|
||||
[false, "kanban"],
|
||||
[false, "form"],
|
||||
],
|
||||
context: {
|
||||
group_by: ["date"],
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsOnce(target, ".o_kanban_view");
|
||||
assert.containsN(target, ".o_kanban_group", 2);
|
||||
assert.containsNone(target, ".o_column_folded");
|
||||
assert.containsN(target, ".o_kanban_record", 4);
|
||||
|
||||
// fold the second column
|
||||
const clickColumnAction = await toggleColumnActions(1);
|
||||
await clickColumnAction("Fold");
|
||||
assert.containsOnce(target, ".o_column_folded");
|
||||
assert.containsOnce(target, ".o_kanban_record");
|
||||
|
||||
// open a record and go back
|
||||
await click(target.querySelector(".o_kanban_record"));
|
||||
assert.containsOnce(target, ".o_form_view");
|
||||
await click(target.querySelector(".breadcrumb-item a"));
|
||||
assert.containsOnce(target, ".o_column_folded");
|
||||
assert.containsOnce(target, ".o_kanban_record");
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("loaded records are kept when leaving and coming back", async (assert) => {
|
||||
serverData.views = {
|
||||
"partner,false,kanban": `
|
||||
|
||||
@@ -15890,6 +15890,49 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.containsN(target, ".o_data_row", 3);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"open groups are kept when leaving and coming back (grouped by date)",
|
||||
async (assert) => {
|
||||
serverData.models.foo.fields.date.default = "2022-10-10";
|
||||
serverData.views = {
|
||||
"foo,false,list": `<tree><field name="foo"/></tree>`,
|
||||
"foo,false,search": "<search/>",
|
||||
"foo,false,form": "<form/>",
|
||||
};
|
||||
const webClient = await createWebClient({ serverData });
|
||||
await doAction(webClient, {
|
||||
name: "Partners",
|
||||
res_model: "foo",
|
||||
type: "ir.actions.act_window",
|
||||
views: [
|
||||
[false, "list"],
|
||||
[false, "form"],
|
||||
],
|
||||
context: {
|
||||
group_by: ["date"],
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsOnce(target, ".o_list_view");
|
||||
assert.containsN(target, ".o_group_header", 2);
|
||||
assert.containsNone(target, ".o_group_open");
|
||||
assert.containsNone(target, ".o_data_row");
|
||||
|
||||
// unfold the second group
|
||||
await click(target.querySelectorAll(".o_group_header")[1]);
|
||||
assert.containsOnce(target, ".o_group_open");
|
||||
assert.containsN(target, ".o_data_row", 3);
|
||||
|
||||
// open a record and go back
|
||||
await click(target.querySelector(".o_data_cell"));
|
||||
assert.containsOnce(target, ".o_form_view");
|
||||
await click(target.querySelector(".breadcrumb-item a"));
|
||||
|
||||
assert.containsOnce(target, ".o_group_open");
|
||||
assert.containsN(target, ".o_data_row", 3);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"go to the next page after leaving and coming back to a grouped list view",
|
||||
async (assert) => {
|
||||
|
||||
Reference in New Issue
Block a user