diff --git a/addons/web/static/src/core/py_js/py_date.js b/addons/web/static/src/core/py_js/py_date.js index 768232c3c00..3259e171c77 100644 --- a/addons/web/static/src/core/py_js/py_date.js +++ b/addons/web/static/src/core/py_js/py_date.js @@ -362,6 +362,21 @@ export class PyDateTime { toJSON() { return this.strftime("%Y-%m-%d %H:%M:%S"); } + + to_utc() { + const d = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second); + const offset = d.getTimezoneOffset(); + // previous implementation did use timedelta + const s = tmxxx( + this.year, + this.month, + this.day, + this.hour, + this.minute, + this.second + 60 * offset + ); + return new PyDateTime(s.year, s.month, s.day, s.hour, s.minute, s.second); + } } export class PyTime extends PyDate { diff --git a/addons/web/static/tests/core/py_js/py_date_tests.js b/addons/web/static/tests/core/py_js/py_date_tests.js index c962a86c164..f65b1887809 100644 --- a/addons/web/static/tests/core/py_js/py_date_tests.js +++ b/addons/web/static/tests/core/py_js/py_date_tests.js @@ -1,6 +1,7 @@ /** @odoo-module **/ import { evaluateExpr } from "@web/core/py_js/py"; +import { patchDate, patchWithCleanup } from "@web/../tests/helpers/utils"; QUnit.module("py", {}, () => { QUnit.module("date stuff", () => { @@ -55,6 +56,20 @@ QUnit.module("py", {}, () => { assert.strictEqual(evaluateExpr(expr3), "2001-04-03 00:32:12"); }); + QUnit.test("to_utc", (assert) => { + patchDate(2021, 8, 17, 10, 0, 0); + patchWithCleanup(Date.prototype, { + getTimezoneOffset() { + return -360; + }, + }); + + const expr = + "datetime.datetime.combine(context_today(), datetime.time(0,0,0)).to_utc()"; + + assert.strictEqual(JSON.stringify(evaluateExpr(expr)), `"2021-09-16 18:00:00"`); + }); + QUnit.test("datetime.datetime.combine", (assert) => { const expr = "datetime.datetime.combine(context_today(), datetime.time(23,59,59)).strftime('%Y-%m-%d %H:%M:%S')"; diff --git a/addons/web/static/tests/search/search_model_tests.js b/addons/web/static/tests/search/search_model_tests.js index ca723b54c91..881d1bea7bd 100644 --- a/addons/web/static/tests/search/search_model_tests.js +++ b/addons/web/static/tests/search/search_model_tests.js @@ -2,6 +2,7 @@ import { patchDate } from "@web/../tests/helpers/utils"; import { makeWithSearch, setupControlPanelServiceRegistry } from "./helpers"; +import { patchWithCleanup } from "@web/../tests/helpers/utils"; const { Component, tags } = owl; const { xml } = tags; @@ -777,4 +778,36 @@ QUnit.module("Search", (hooks) => { ]); assert.deepEqual(model.groupBy, ["date_field:month"]); }); + + QUnit.test("dynamic domains evaluation", async function (assert) { + patchDate(2021, 8, 17, 10, 0, 0); + + patchWithCleanup(Date.prototype, { + getTimezoneOffset() { + return -120; + }, + }); + + const searchViewArch = ` + + + + + + `; + + const evaluatedDomains = [ + [["datetime", "=", "2021-09-16 22:00:00"]], + [["date", "=", "2020-09-17 00:00:00"]], + [["create_date", ">", "2021-09-16"]], + ]; + + const model = await makeSearchModel({ serverData, searchViewArch }); + + for (let i = 0; i < evaluatedDomains.length; i++) { + model.toggleSearchItem(i + 1); + assert.deepEqual(model.domain, evaluatedDomains[i]); + model.toggleSearchItem(i + 1); + } + }); });