[FIX] web: sample server grouped by a date range
Have a kanban view by default grouped by a date field, with a granularity eg: "date:month". Have no data so that the read group returns with only the groups for the range (fill temporal). Those groups should have a count of zero, triggering the sample server to make up data. Before this commit, there were multiple crashes basically because the groupby written as field:granularity was not handled at least in the case were groups are returned by the server. That is, from the sample server perspective, groups are reused and records are just made up matching those groups. There were two issues in fact: - the groupBy with granularity (eg: date:month) was not properly handled, sometimes not splitting the field name and the granularity, sometimes splitting those up where it should not. - since the RelationalModel's groups are re-used verbatim by the sample server (which still needs to return what the real web_read_group would), the "__range" data was missing, since it had been transformed by the RelationalModel after the real call to web_read_group to the server. After this commit, this use case is supported. opw-3063067 closes odoo/odoo#107529 X-original-commit: 060b237f3caac5241130915b41a34aab7d28f4cb Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
This commit is contained in:
@@ -505,7 +505,7 @@ export class SampleServer {
|
||||
* @return {Object}
|
||||
*/
|
||||
_mockReadProgressBar(params) {
|
||||
const groupBy = params.group_by;
|
||||
const groupBy = params.group_by.split(":")[0];
|
||||
const progress_bar = params.progress_bar;
|
||||
const groupByField = this.data[params.model].fields[groupBy];
|
||||
const data = {};
|
||||
@@ -599,7 +599,7 @@ export class SampleServer {
|
||||
_populateExistingGroups(params) {
|
||||
if (!this.existingGroupsPopulated) {
|
||||
const groups = this.existingGroups;
|
||||
const groupBy = params.groupBy[0];
|
||||
const groupBy = params.groupBy[0].split(":")[0];
|
||||
const groupByField = this.data[params.model].fields[groupBy];
|
||||
const groupedByM2O = groupByField.type === "many2one";
|
||||
if (groupedByM2O) {
|
||||
@@ -671,12 +671,13 @@ export class SampleServer {
|
||||
this._populateExistingGroups(params);
|
||||
|
||||
// update count and aggregates for each group
|
||||
const groupBy = params.groupBy[0].split(":")[0];
|
||||
const fullGroupBy = params.groupBy[0];
|
||||
const groupBy = fullGroupBy.split(":")[0];
|
||||
const records = this.data[params.model].records;
|
||||
for (const g of groups) {
|
||||
const recordsInGroup = records.filter((r) => r[groupBy] === g.value);
|
||||
g[`${groupBy}_count`] = recordsInGroup.length;
|
||||
g[groupBy] = [g.value, g.displayName];
|
||||
g[fullGroupBy] = [g.value, g.displayName];
|
||||
for (const field of params.fields) {
|
||||
const fieldType = this.data[params.model].fields[field].type;
|
||||
if (["integer, float", "monetary"].includes(fieldType)) {
|
||||
@@ -690,6 +691,7 @@ export class SampleServer {
|
||||
}),
|
||||
length: recordsInGroup.length,
|
||||
};
|
||||
g.__range = { ...g.range };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6657,6 +6657,67 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.containsOnce(target, ".o_kanban_example_background_container");
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"empty kanban with sample data grouped by date range (fill temporal)",
|
||||
async (assert) => {
|
||||
serverData.models.partner.records = [];
|
||||
|
||||
await makeView({
|
||||
arch: `
|
||||
<kanban sample="1">
|
||||
<field name="date" allow_group_range_value="true"/>
|
||||
<field name="state"/>
|
||||
<field name="int_field"/>
|
||||
<progressbar field="state" sum_field="int_field" help="progress" colors="{}"/>
|
||||
<templates>
|
||||
<div t-name="kanban-box">
|
||||
<field name="foo"/>
|
||||
<field name="int_field"/>
|
||||
</div>
|
||||
</templates>
|
||||
</kanban>`,
|
||||
serverData,
|
||||
groupBy: ["date:month"],
|
||||
resModel: "partner",
|
||||
type: "kanban",
|
||||
noContentHelp: "No content helper",
|
||||
mockRPC(route, args) {
|
||||
if (args.method === "web_read_group") {
|
||||
// Simulate fill temporal
|
||||
return {
|
||||
groups: [
|
||||
{
|
||||
date_count: 0,
|
||||
state: false,
|
||||
"date:month": "December 2022",
|
||||
__range: {
|
||||
"date:month": {
|
||||
from: "2022-12-01",
|
||||
to: "2023-01-01",
|
||||
},
|
||||
},
|
||||
__domain: [
|
||||
["date", ">=", "2022-12-01"],
|
||||
["date", "<", "2023-01-01"],
|
||||
],
|
||||
},
|
||||
],
|
||||
length: 1,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsOnce(target, ".o_view_nocontent");
|
||||
assert.strictEqual(
|
||||
target.querySelector(".o_kanban_group .o_column_title").textContent,
|
||||
"December 2022"
|
||||
);
|
||||
assert.containsOnce(target, ".o_kanban_group");
|
||||
assert.containsN(target, ".o_kanban_group .o_kanban_record", 16);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("empty grouped kanban with sample data and click quick create", async (assert) => {
|
||||
await makeView({
|
||||
type: "kanban",
|
||||
|
||||
Reference in New Issue
Block a user