From 286eee33203982a734faf9641bef14250f42e61b Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Wed, 28 Sep 2022 14:03:20 +0000 Subject: [PATCH] [FIX] web: prevent selecting an invalid scale in calendar By pressing the date in the calendar's date picker, a function computes a new scale to be used depending on the previous focused date and scale, for example clicking on the focused date in month scale will switch to week and so on. However it bypasses the scales that are available on the calendar's definition. It is now prevented. X-original-commit: a9059b0bee02f635d563b45ee94f04bab5532fe4 Part-of: odoo/odoo#101603 --- .../static/src/views/calendar/calendar_model.js | 4 ++++ .../tests/views/calendar/calendar_view_tests.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/addons/web/static/src/views/calendar/calendar_model.js b/addons/web/static/src/views/calendar/calendar_model.js index 17a7f08f6d3..891cbdc1aaa 100644 --- a/addons/web/static/src/views/calendar/calendar_model.js +++ b/addons/web/static/src/views/calendar/calendar_model.js @@ -45,6 +45,10 @@ export class CalendarModel extends Model { ? deserializeDateTime(params.context.initial_date) : luxon.DateTime.local(); } + // Prevent picking a scale that is not supported by the view + if (!this.meta.scales.includes(this.meta.scale)) { + this.meta.scale = this.meta.scales[0]; + } const data = { ...this.data }; await this.keepLast.add(this.updateData(data)); this.data = data; diff --git a/addons/web/static/tests/views/calendar/calendar_view_tests.js b/addons/web/static/tests/views/calendar/calendar_view_tests.js index 042d7cac229..4085b374af4 100644 --- a/addons/web/static/tests/views/calendar/calendar_view_tests.js +++ b/addons/web/static/tests/views/calendar/calendar_view_tests.js @@ -3934,4 +3934,21 @@ QUnit.module("Views", ({ beforeEach }) => { // test would fail here if we don't ignore readonly modifier assert.containsOnce(target, ".o_cw_popover"); }); + + QUnit.test("can not select invalid scale from datepicker", async (assert) => { + await makeView({ + type: "calendar", + resModel: "event", + serverData, + arch: ` + + + + `, + }); + + await click(target, ".ui-datepicker-today"); + // test would fail here if we went to week mode + assert.containsOnce(target, ".fc-dayGridMonth-view"); + }); });