[FIX] spreadsheet: correctly format date/datetime values of list
Before this revision, a date/datetime field was displayed in UTC instead of in the user timezone. This revision fixes this issue. opw 3127742 closes odoo/odoo#117623 X-original-commit: c07b450594f7e3e1f093d0b5a5a083f915f75310 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com> Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
This commit is contained in:
committed by
Lucas Lefèvre
parent
a226e2317b
commit
70a2a62ec9
@@ -5,6 +5,12 @@ import { LoadingDataError } from "@spreadsheet/o_spreadsheet/errors";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
import { orderByToString } from "@web/views/utils";
|
||||
import {
|
||||
formatDateTime,
|
||||
deserializeDateTime,
|
||||
formatDate,
|
||||
deserializeDate,
|
||||
} from "@web/core/l10n/dates";
|
||||
|
||||
import * as spreadsheet from "@odoo/o-spreadsheet";
|
||||
|
||||
@@ -152,8 +158,9 @@ export default class ListDataSource extends OdooViewsDataSource {
|
||||
case "boolean":
|
||||
return record[fieldName] ? "TRUE" : "FALSE";
|
||||
case "date":
|
||||
return record[fieldName] ? toNumber(this._formatDate(record[fieldName])) : "";
|
||||
case "datetime":
|
||||
return record[fieldName] ? toNumber(record[fieldName]) : "";
|
||||
return record[fieldName] ? toNumber(this._formatDateTime(record[fieldName])) : "";
|
||||
default:
|
||||
return record[fieldName] || "";
|
||||
}
|
||||
@@ -163,6 +170,16 @@ export default class ListDataSource extends OdooViewsDataSource {
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
_formatDateTime(dateValue) {
|
||||
const date = deserializeDateTime(dateValue);
|
||||
return formatDateTime(date);
|
||||
}
|
||||
|
||||
_formatDate(dateValue) {
|
||||
const date = deserializeDate(dateValue);
|
||||
return formatDate(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the parent data source to force a reload of this data source in the
|
||||
* next clock cycle. It's necessary when this.limit was updated and new
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { ormService } from "@web/core/orm_service";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { makeFakeLocalizationService } from "@web/../tests/helpers/mock_services";
|
||||
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
|
||||
import { nextTick } from "@web/../tests/helpers/utils";
|
||||
|
||||
@@ -31,6 +32,7 @@ export function setupDataSourceEvaluation(model) {
|
||||
*/
|
||||
export async function createModelWithDataSource(params = {}) {
|
||||
registry.category("services").add("orm", ormService, { force: true });
|
||||
registry.category("services").add("localization", makeFakeLocalizationService(), { force: true });
|
||||
const env = await makeTestEnv({
|
||||
serverData: params.serverData || getBasicServerData(),
|
||||
mockRPC: params.mockRPC,
|
||||
|
||||
Reference in New Issue
Block a user