[FIX] web: wrong UTC convert in constructDateRange
Before this commit: - Let's say we are in January 2023 - User's TZ has an offset from UTC (say UTC+2) - Purchase > Create an rfq - Set order deadline to 1st of next month (February), at 0.05am - Add some products - Confirm order - Go to Reporting > Purchase then pivot view - Add a filter on Order Date for the current month (January) - Collapse the row groupbys - Group the rows by Order Data > Month - You can see the record of February and it should not be seeable. After this commit - the date range is now properly computed closes odoo/odoo#111847 X-original-commit: 20c9e473419b92bbed01617c494b75847c60eea9 Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com> Signed-off-by: Bruno Boi (boi) <boi@odoo.com> Co-authored-by: Kristjan Tehu <kristjan.tehu@estpos.ee>
This commit is contained in:
co-authored by
Kristjan Tehu
parent
1e2923edee
commit
277ff4f469
@@ -210,10 +210,7 @@ export function constructDateRange(params) {
|
||||
setParam.month = QUARTERS[setParam.quarter].coveredMonths[0];
|
||||
delete setParam.quarter;
|
||||
}
|
||||
const date = referenceMoment
|
||||
.set(setParam)
|
||||
.plus(plusParam || {})
|
||||
.setZone("utc", { keepLocalTime: true });
|
||||
const date = referenceMoment.set(setParam).plus(plusParam || {});
|
||||
// compute domain
|
||||
const leftDate = date.startOf(granularity);
|
||||
const rightDate = date.endOf(granularity);
|
||||
|
||||
@@ -6,18 +6,78 @@ import { Domain } from "@web/core/domain";
|
||||
import { localization } from "@web/core/l10n/localization";
|
||||
import { patch, unpatch } from "@web/core/utils/patch";
|
||||
import { patchDate } from "@web/../tests/helpers/utils";
|
||||
import { registerCleanup } from "@web/../tests/helpers/cleanup";
|
||||
import { translatedTerms } from "@web/core/l10n/translation";
|
||||
|
||||
const { DateTime } = luxon;
|
||||
|
||||
function patchTimeZone(offset) {
|
||||
const fixedZone = new luxon.FixedOffsetZone.instance(offset);
|
||||
const originalZone = luxon.Settings.defaultZone;
|
||||
luxon.Settings.defaultZone = fixedZone.name;
|
||||
registerCleanup(() => {
|
||||
luxon.Settings.defaultZone = originalZone;
|
||||
});
|
||||
}
|
||||
|
||||
QUnit.module("Search", () => {
|
||||
QUnit.module("SearchUtils");
|
||||
QUnit.module("SearchUtils", {
|
||||
beforeEach() {
|
||||
patchTimeZone(0);
|
||||
},
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"construct simple domain based on date field (no comparisonOptionId)",
|
||||
function (assert) {
|
||||
patchDate(2020, 5, 1, 13, 0, 0);
|
||||
const referenceMoment = DateTime.utc();
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(constructDateDomain(referenceMoment, "date_field", "date", []), {
|
||||
domain: new Domain(`[]`),
|
||||
description: "",
|
||||
});
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "date", [
|
||||
"this_month",
|
||||
"this_year",
|
||||
]),
|
||||
{
|
||||
domain: new Domain(
|
||||
`["&", ("date_field", ">=", "2020-06-01"), ("date_field", "<=", "2020-06-30")]`
|
||||
),
|
||||
description: "June 2020",
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "date", [
|
||||
"second_quarter",
|
||||
"this_year",
|
||||
]),
|
||||
{
|
||||
domain: new Domain(
|
||||
`["&", ("date_field", ">=", "2020-04-01"), ("date_field", "<=", "2020-06-30")]`
|
||||
),
|
||||
description: "Q2 2020",
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "date", ["this_year"]),
|
||||
{
|
||||
domain: new Domain(
|
||||
`["&", ("date_field", ">=", "2020-01-01"), ("date_field", "<=", "2020-12-31")]`
|
||||
),
|
||||
description: "2020",
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"construct simple domain based on date field (no comparisonOptionId) - UTC+2",
|
||||
(assert) => {
|
||||
patchTimeZone(120);
|
||||
patchDate(2020, 5, 1, 0, 0, 0);
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(constructDateDomain(referenceMoment, "date_field", "date", []), {
|
||||
domain: new Domain(`[]`),
|
||||
description: "",
|
||||
@@ -62,7 +122,7 @@ QUnit.module("Search", () => {
|
||||
"construct simple domain based on datetime field (no comparisonOptionId)",
|
||||
function (assert) {
|
||||
patchDate(2020, 5, 1, 13, 0, 0);
|
||||
const referenceMoment = DateTime.utc();
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "datetime", [
|
||||
"this_month",
|
||||
@@ -98,9 +158,52 @@ QUnit.module("Search", () => {
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"construct simple domain based on datetime field (no comparisonOptionId) - UTC+2",
|
||||
(assert) => {
|
||||
patchTimeZone(120);
|
||||
patchDate(2020, 5, 1, 0, 0, 0);
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "datetime", [
|
||||
"this_month",
|
||||
"this_year",
|
||||
]),
|
||||
{
|
||||
domain: new Domain(
|
||||
`["&", ("date_field", ">=", "2020-05-31 22:00:00"), ("date_field", "<=", "2020-06-30 21:59:59")]`
|
||||
),
|
||||
description: "June 2020",
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "datetime", [
|
||||
"second_quarter",
|
||||
"this_year",
|
||||
]),
|
||||
{
|
||||
domain: new Domain(
|
||||
`["&", ("date_field", ">=", "2020-03-31 22:00:00"), ("date_field", "<=", "2020-06-30 21:59:59")]`
|
||||
),
|
||||
description: "Q2 2020",
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "datetime", ["this_year"]),
|
||||
{
|
||||
domain: new Domain(
|
||||
`["&", ("date_field", ">=", "2019-12-31 22:00:00"), ("date_field", "<=", "2020-12-31 21:59:59")]`
|
||||
),
|
||||
description: "2020",
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("construct domain based on date field (no comparisonOptionId)", function (assert) {
|
||||
patchDate(2020, 0, 1, 12, 0, 0);
|
||||
const referenceMoment = DateTime.utc();
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "date", [
|
||||
"this_month",
|
||||
@@ -158,7 +261,7 @@ QUnit.module("Search", () => {
|
||||
"construct domain based on datetime field (no comparisonOptionId)",
|
||||
function (assert) {
|
||||
patchDate(2020, 0, 1, 12, 0, 0);
|
||||
const referenceMoment = DateTime.utc();
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "datetime", [
|
||||
"this_month",
|
||||
@@ -217,7 +320,7 @@ QUnit.module("Search", () => {
|
||||
'construct comparison domain based on date field and option "previous_period"',
|
||||
function (assert) {
|
||||
patchDate(2020, 0, 1, 12, 0, 0);
|
||||
const referenceMoment = DateTime.utc();
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(
|
||||
constructDateDomain(
|
||||
referenceMoment,
|
||||
@@ -326,7 +429,7 @@ QUnit.module("Search", () => {
|
||||
'construct comparison domain based on datetime field and option "previous_year"',
|
||||
function (assert) {
|
||||
patchDate(2020, 5, 1, 13, 0, 0);
|
||||
const referenceMoment = DateTime.utc();
|
||||
const referenceMoment = DateTime.local();
|
||||
assert.deepEqual(
|
||||
constructDateDomain(
|
||||
referenceMoment,
|
||||
@@ -393,7 +496,7 @@ QUnit.module("Search", () => {
|
||||
|
||||
QUnit.test("Quarter option: custom translation", async function (assert) {
|
||||
patchDate(2020, 5, 1, 13, 0, 0);
|
||||
const referenceMoment = DateTime.utc().setLocale("en");
|
||||
const referenceMoment = DateTime.local().setLocale("en");
|
||||
patch(translatedTerms, "add_translations", { Q2: "Deuxième trimestre de l'an de grâce" });
|
||||
assert.deepEqual(
|
||||
constructDateDomain(referenceMoment, "date_field", "date", [
|
||||
@@ -413,7 +516,7 @@ QUnit.module("Search", () => {
|
||||
|
||||
QUnit.test("Quarter option: right to left", async function (assert) {
|
||||
patchDate(2020, 5, 1, 13, 0, 0);
|
||||
const referenceMoment = DateTime.utc().setLocale("en");
|
||||
const referenceMoment = DateTime.local().setLocale("en");
|
||||
patch(
|
||||
localization,
|
||||
"rtl_localization",
|
||||
@@ -437,7 +540,7 @@ QUnit.module("Search", () => {
|
||||
|
||||
QUnit.test("Quarter option: custom translation and right to left", async function (assert) {
|
||||
patchDate(2020, 5, 1, 13, 0, 0);
|
||||
const referenceMoment = DateTime.utc().setLocale("en");
|
||||
const referenceMoment = DateTime.local().setLocale("en");
|
||||
patch(
|
||||
localization,
|
||||
"rtl_localization",
|
||||
|
||||
Reference in New Issue
Block a user