From 0fa9b07d8fe24f583f4fa3fb5c24cda471e1e9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Mon, 27 Feb 2023 08:08:23 +0000 Subject: [PATCH] [FIX] documents_spreadsheet: use user timezone for pivot view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set the user timezone to Australia/Sydney (GMT+11) Set your computer's timezone is US/Arizona (GMT-7) Insert a pivot view grouped by a datetime field (e.g. create_date), The dates are messed up. The server returns midnight in Sydney, as UTC as always in odoo 2023-01-01 00:00:00 in Sydney is 2022-12-31 13:00:00 in UTC Since midnight in Sydney is still the previous day in UTC, we have to convert the datetime to the original timezone to get back the local date (2023-01-01). If the user timezone and the computer timezone are different, using the computer timezone is wrong because it will yield the time in Arizona. When it's midnight in Sydney (2023-01-01 00:00:00) it's 2022-12-31 06:00:00 in Arizona. This is not the same day! opw-3170077 closes odoo/odoo#113740 X-original-commit: b2f760cae74201d1622e56a0027dae67dcff9e33 Signed-off-by: Lucas Lefèvre (lul) --- addons/spreadsheet/static/src/pivot/pivot_model.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/spreadsheet/static/src/pivot/pivot_model.js b/addons/spreadsheet/static/src/pivot/pivot_model.js index 69045656e2c..55e006e7588 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_model.js +++ b/addons/spreadsheet/static/src/pivot/pivot_model.js @@ -5,6 +5,7 @@ import { Domain } from "@web/core/domain"; import { sprintf } from "@web/core/utils/strings"; import { PivotModel } from "@web/views/pivot/pivot_model"; import { computeReportMeasures } from "@web/views/utils"; +import { session } from "@web/session"; import { FORMATS } from "../helpers/constants"; @@ -482,7 +483,8 @@ export class SpreadsheetPivotModel extends PivotModel { if (this.metaData.fields[field.name].type === "date") { return sqlValue; } - return luxon.DateTime.fromSQL(sqlValue, { zone: "utc" }).toLocal().toISODate(); + const userTz = session.user_context.tz || luxon.Settings.defaultZoneName; + return luxon.DateTime.fromSQL(sqlValue, { zone: "utc" }).setZone(userTz).toISODate(); } /**