From ec86454778fbf0e5f52f45a7c5d82ece9a07c82b Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Thu, 20 Oct 2022 17:27:55 +0000 Subject: [PATCH] [FIX] web: legacy kanbanRecord kinda supports luxon The new WOWL Kanban view supports that luxon be used in the archs. Legacy kanban had a similar support but for moment.js Obviously, new archs can't work with legacy implementation because of this. This commit aims at providing some sort of hackish support, only valid in the transition phase. At least one use case has popped up, that is, when editing such kanban view with Studio. In that case, there was a crash, which is fixed with this commit. closes odoo/odoo#103821 X-original-commit: 14f56b324d241f35b742781424535cecf26a218e Signed-off-by: Aaron Bohy (aab) Signed-off-by: Lucas Perais (lpe) --- .../legacy/js/views/kanban/kanban_record.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addons/web/static/src/legacy/js/views/kanban/kanban_record.js b/addons/web/static/src/legacy/js/views/kanban/kanban_record.js index 828fd89f839..51a53a71273 100644 --- a/addons/web/static/src/legacy/js/views/kanban/kanban_record.js +++ b/addons/web/static/src/legacy/js/views/kanban/kanban_record.js @@ -26,6 +26,25 @@ var NB_KANBAN_RECORD_COLORS = KANBAN_RECORD_COLORS.length; const { Component } = owl; +const { DateTime } = luxon; +// As the name suggests, this is a hack that allows archs that work in the new +// WOWL kanban views to be instanciated with legacy code. This is one of some +// hacks to make this work, until the legacy code base is deleted. +// It only exposes `fromISO` and `local` of DateTime, to limit the damage and complexity. +const hackishLuxon = { + DateTime: { + fromISO(text, opt) { + // In legacy text should be a Date (native JS) object (see @_transformRecord) + const res = DateTime.fromJSDate(text, "UTC"); + if (!res.isValid) { + throw new Error("Invalid Hackish luxon instance in legacy KanbanRecord") + } + return res; + }, + local: DateTime.local, + } +}; + var KanbanRecord = Widget.extend(WidgetAdapterMixin, { events: { 'click .oe_kanban_action': '_onKanbanActionClicked', @@ -593,6 +612,7 @@ var KanbanRecord = Widget.extend(WidgetAdapterMixin, { record: this.record, user_context: this.getSession().user_context, widget: this, + luxon: hackishLuxon, }; }, /**