[FIX] documents_spreadsheet: use user timezone for pivot view

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) <lul@odoo.com>
This commit is contained in:
Lucas Lefèvre
2023-02-27 15:00:19 +01:00
parent 0d6d5883ad
commit 0fa9b07d8f
@@ -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();
}
/**