[FIX] web: invalid datetime range/domain in mockReadGroup
The mock server's mockReadGroup function would not properly compute the
range and domain of the returned groups for datetime fields with groupby
hour.
The year of the range/domain should be the same as the record and not
the current year.
Consider the following:
- a record with a datetime field of value "2016-12-14 12:34:56".
- a read_group with groupby "['datetime:hour']"
The corresponding group would have had the following metadata (considering current year is 2022):
- value: `"13:00 14 Dec"`
- domain: `[["datetime", ">=", "2022-12-14 12:00:00"], ["datetime", "<", "2022-12-14 13:00:00"]]`
- range: `{ from: "2022-12-14 12:00:00", to: "2022-12-14 13:00:00" }`
It now has the following valid metadata:
- value: `"13:00 14 Dec"`
- domain: `[["datetime", ">=", "2016-12-14 12:00:00"], ["datetime", "<", "2016-12-14 13:00:00"]]`
- range: `{ from: "2016-12-14 12:00:00", to: "2016-12-14 13:00:00" }`
X-original-commit: cca1fad650efc13cd1695acb723b9aa9a54ba184
Part-of: odoo/odoo#108947
Co-authored-by: Bruno Boi <boi@odoo.com>
This commit is contained in:
co-authored by
Bruno Boi
parent
f9a5020094
commit
fc47ddc2f2
@@ -499,9 +499,9 @@ export class MockServer {
|
||||
}
|
||||
|
||||
_modifiersFromModel(node) {
|
||||
const modifiersNames = ['invisible'];
|
||||
if (['kanban', 'tree', 'form'].includes(node.tagName)) {
|
||||
modifiersNames.push(...['readonly', 'required']);
|
||||
const modifiersNames = ["invisible"];
|
||||
if (["kanban", "tree", "form"].includes(node.tagName)) {
|
||||
modifiersNames.push(...["readonly", "required"]);
|
||||
}
|
||||
return modifiersNames;
|
||||
}
|
||||
@@ -1001,7 +1001,9 @@ export class MockServer {
|
||||
} else if (type === "datetime") {
|
||||
const date = deserializeDateTime(val);
|
||||
if (aggregateFunction === "hour") {
|
||||
return date.toFormat("HH:00 dd MMM");
|
||||
// The year is added to the format because is needed to correctly compute the
|
||||
// domain and the range (startDate and endDate).
|
||||
return date.toFormat("HH:00 dd MMM yyyy");
|
||||
} else if (aggregateFunction === "day") {
|
||||
return date.toFormat("yyyy-MM-dd");
|
||||
} else if (aggregateFunction === "week") {
|
||||
@@ -1093,12 +1095,11 @@ export class MockServer {
|
||||
let startDate, endDate;
|
||||
switch (dateRange) {
|
||||
case "hour": {
|
||||
try {
|
||||
startDate = parseDateTime(value, { format: "HH dd MMM" });
|
||||
} catch {
|
||||
startDate = parseDateTime(value, { format: "HH:00 dd MMM" });
|
||||
}
|
||||
startDate = parseDateTime(value, { format: "HH:00 dd MMM yyyy" });
|
||||
endDate = startDate.plus({ hours: 1 });
|
||||
// Remove the year from the result value of the group. It was needed
|
||||
// to compute the startDate and endDate.
|
||||
group[gbField] = startDate.toFormat("HH:00 dd MMM");
|
||||
break;
|
||||
}
|
||||
case "day": {
|
||||
|
||||
@@ -612,7 +612,7 @@ QUnit.module("MockServer", (hooks) => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.skip("performRPC: read_group, group by datetime", async function (assert) {
|
||||
QUnit.test("performRPC: read_group, group by datetime", async function (assert) {
|
||||
const server = new MockServer(data, {});
|
||||
let result = await server.performRPC("", {
|
||||
model: "bar",
|
||||
@@ -685,35 +685,35 @@ QUnit.module("MockServer", (hooks) => {
|
||||
result.map((x) => x.__domain),
|
||||
[
|
||||
[
|
||||
["datetime", ">=", "2022-04-11 12:00:00"],
|
||||
["datetime", "<", "2022-04-11 13:00:00"],
|
||||
["datetime", ">=", "2016-04-11 12:00:00"],
|
||||
["datetime", "<", "2016-04-11 13:00:00"],
|
||||
],
|
||||
[
|
||||
["datetime", ">=", "2022-10-26 12:00:00"],
|
||||
["datetime", "<", "2022-10-26 13:00:00"],
|
||||
["datetime", ">=", "2016-10-26 12:00:00"],
|
||||
["datetime", "<", "2016-10-26 13:00:00"],
|
||||
],
|
||||
[
|
||||
["datetime", ">=", "2022-12-14 12:00:00"],
|
||||
["datetime", "<", "2022-12-14 13:00:00"],
|
||||
["datetime", ">=", "2016-12-14 12:00:00"],
|
||||
["datetime", "<", "2016-12-14 13:00:00"],
|
||||
],
|
||||
[
|
||||
["datetime", ">=", "2022-12-15 12:00:00"],
|
||||
["datetime", "<", "2022-12-15 13:00:00"],
|
||||
["datetime", ">=", "2016-12-15 12:00:00"],
|
||||
["datetime", "<", "2016-12-15 13:00:00"],
|
||||
],
|
||||
[
|
||||
["datetime", ">=", "2022-12-30 12:00:00"],
|
||||
["datetime", "<", "2022-12-30 13:00:00"],
|
||||
["datetime", ">=", "2019-12-30 12:00:00"],
|
||||
["datetime", "<", "2019-12-30 13:00:00"],
|
||||
],
|
||||
]
|
||||
);
|
||||
assert.deepEqual(
|
||||
result.map((x) => x.__range["datetime:hour"]),
|
||||
[
|
||||
{ from: "2022-04-11 12:00:00", to: "2022-04-11 13:00:00" },
|
||||
{ from: "2022-10-26 12:00:00", to: "2022-10-26 13:00:00" },
|
||||
{ from: "2022-12-14 12:00:00", to: "2022-12-14 13:00:00" },
|
||||
{ from: "2022-12-15 12:00:00", to: "2022-12-15 13:00:00" },
|
||||
{ from: "2022-12-30 12:00:00", to: "2022-12-30 13:00:00" },
|
||||
{ from: "2016-04-11 12:00:00", to: "2016-04-11 13:00:00" },
|
||||
{ from: "2016-10-26 12:00:00", to: "2016-10-26 13:00:00" },
|
||||
{ from: "2016-12-14 12:00:00", to: "2016-12-14 13:00:00" },
|
||||
{ from: "2016-12-15 12:00:00", to: "2016-12-15 13:00:00" },
|
||||
{ from: "2019-12-30 12:00:00", to: "2019-12-30 13:00:00" },
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user