diff --git a/addons/web/static/src/views/sample_server.js b/addons/web/static/src/views/sample_server.js index 1d7c5ce7969..4eb5b8fefb3 100644 --- a/addons/web/static/src/views/sample_server.js +++ b/addons/web/static/src/views/sample_server.js @@ -18,6 +18,17 @@ function getSampleFromId(id, sampleTexts) { return sampleTexts[(id - 1) % sampleTexts.length]; } +function serializeGroupValue(value, type) { + switch (type) { + case "date": + return serializeDate(value); + case "datetime": + return serializeDateTime(value); + default: + return value; + } +} + /** * Helper function returning a regular expression specifically matching * a given 'term' in a fieldName. For example `fieldNameRegex('abc')`: @@ -603,7 +614,7 @@ export class SampleServer { } for (const r of this.data[params.model].records) { const group = getSampleFromId(r.id, groups); - r[groupBy] = group.value; + r[groupBy] = serializeGroupValue(group.value, groupByField.type); } this.existingGroupsPopulated = true; } @@ -666,9 +677,12 @@ export class SampleServer { // update count and aggregates for each group const fullGroupBy = params.groupBy[0]; const groupBy = fullGroupBy.split(":")[0]; + const groupByField = this.data[params.model].fields[groupBy]; const records = this.data[params.model].records; for (const g of groups) { - const recordsInGroup = records.filter((r) => r[groupBy] === g.value); + const recordsInGroup = records.filter((r) => { + return r[groupBy] === serializeGroupValue(g.value, groupByField.type); + }); g[`${groupBy}_count`] = recordsInGroup.length; g[fullGroupBy] = g.__rawValue; for (const field of params.fields) { diff --git a/addons/web/static/tests/webclient/actions/window_action_tests.js b/addons/web/static/tests/webclient/actions/window_action_tests.js index 1beef63ea31..d3dbf7f3ad1 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -2567,4 +2567,68 @@ QUnit.module("ActionManager", (hooks) => { }); assert.containsOnce(target, ".o_list_view"); }); + + QUnit.test("sample server: populate groups", async function (assert) { + serverData.models.partner.records = []; + serverData.views = { + "partner,false,kanban": ` + + + +
+
+
+
+ `, + "partner,false,pivot": ` + + + + `, + "partner,false,search": ``, + }; + const webClient = await createWebClient({ + serverData, + mockRPC(_, args) { + if (args.method === "web_read_group") { + return { + groups: [ + { + date_count: 0, + "write_date:month": "December 2022", + __range: { + "write_date:month": { + from: "2022-12-01", + to: "2023-01-01", + }, + }, + __domain: [ + ["write_date", ">=", "2022-12-01"], + ["write_date", "<", "2023-01-01"], + ], + }, + ], + length: 1, + }; + } + }, + }); + await doAction(webClient, { + res_id: 1, + type: "ir.actions.act_window", + target: "current", + res_model: "partner", + views: [ + [false, "kanban"], + [false, "pivot"], + ], + }); + + assert.containsOnce(target, ".o_kanban_view .o_view_sample_data"); + assert.strictEqual(target.querySelector(".o_column_title").innerText, "December 2022"); + + await cpHelpers.switchView(target, "pivot"); + + assert.containsOnce(target, ".o_pivot_view .o_view_sample_data"); + }); });