From 4989af021a23cb5573a0be2e18338048bb7dac96 Mon Sep 17 00:00:00 2001 From: ilo Date: Fri, 10 May 2024 10:21:38 -0300 Subject: [PATCH] [16.0][FIX] fixing behavior on slot duration --- web_calendar_slot_duration/README.rst | 11 +++++++++++ web_calendar_slot_duration/readme/CONFIGURE.rst | 11 +++++++++++ .../static/description/index.html | 10 +++++++++- .../static/src/js/calendar_common_renderer.esm.js | 5 ++++- .../static/src/js/calendar_model.esm.js | 9 ++++++++- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/web_calendar_slot_duration/README.rst b/web_calendar_slot_duration/README.rst index 7a60b86f0..8584ab033 100644 --- a/web_calendar_slot_duration/README.rst +++ b/web_calendar_slot_duration/README.rst @@ -47,6 +47,17 @@ action includes a context similar to this (example is the default value):: {"calendar_slot_duration": "00:30:00"} +In addition, you can also configure the calendar view's default mode by adding:: + +{"calendar_slot_duration": "00:30:00", "adapt_view_to_slot_duration": False} + +The ``adapt_view_to_slot_duration`` key is optional and defaults to ``True``. +When set to ``False``, the calendar view will not adapt its view to the slot size. + +For example, if you want to set the default slot duration to 1 hour and 30 minutes, +by default the calendar view will adapt its view to show slots of 1 hour and 30 minutes. +Sometimes this is not desired, for example when you want to show every time slots by hour. + It can be added in actions defined on python or as ``ir.actions.act_window`` records. diff --git a/web_calendar_slot_duration/readme/CONFIGURE.rst b/web_calendar_slot_duration/readme/CONFIGURE.rst index 987abe5b9..55fd5ba82 100644 --- a/web_calendar_slot_duration/readme/CONFIGURE.rst +++ b/web_calendar_slot_duration/readme/CONFIGURE.rst @@ -5,5 +5,16 @@ action includes a context similar to this (example is the default value):: {"calendar_slot_duration": "00:30:00"} +In addition, you can also configure the calendar view's default mode by adding:: + +{"calendar_slot_duration": "00:30:00", "adapt_view_to_slot_duration": False} + +The ``adapt_view_to_slot_duration`` key is optional and defaults to ``True``. +When set to ``False``, the calendar view will not adapt its view to the slot size. + +For example, if you want to set the default slot duration to 1 hour and 30 minutes, +by default the calendar view will adapt its view to show slots of 1 hour and 30 minutes. +Sometimes this is not desired, for example when you want to show every time slots by hour. + It can be added in actions defined on python or as ``ir.actions.act_window`` records. diff --git a/web_calendar_slot_duration/static/description/index.html b/web_calendar_slot_duration/static/description/index.html index 581b8bff5..6a9ab5de6 100644 --- a/web_calendar_slot_duration/static/description/index.html +++ b/web_calendar_slot_duration/static/description/index.html @@ -1,4 +1,3 @@ - @@ -396,6 +395,15 @@ action includes a context similar to this (example is the default value):

 {"calendar_slot_duration": "00:30:00"}
 
+

In addition, you can also configure the calendar view’s default mode by adding:

+
+{"calendar_slot_duration": "00:30:00", "adapt_view_to_slot_duration": False}
+
+

The adapt_view_to_slot_duration key is optional and defaults to True. +When set to False, the calendar view will not adapt its view to the slot size.

+

For example, if you want to set the default slot duration to 1 hour and 30 minutes, +by default the calendar view will adapt its view to show slots of 1 hour and 30 minutes. +Sometimes this is not desired, for example when you want to show every time slots by hour.

It can be added in actions defined on python or as ir.actions.act_window records.

diff --git a/web_calendar_slot_duration/static/src/js/calendar_common_renderer.esm.js b/web_calendar_slot_duration/static/src/js/calendar_common_renderer.esm.js index acbff978d..23ff9b09f 100644 --- a/web_calendar_slot_duration/static/src/js/calendar_common_renderer.esm.js +++ b/web_calendar_slot_duration/static/src/js/calendar_common_renderer.esm.js @@ -11,7 +11,10 @@ patch( { get options() { const options = this._super(...arguments); - if (this.env.searchModel.context.calendar_slot_duration) { + if ( + this.env.searchModel.context.calendar_slot_duration && + !this.env.searchModel.context.keep_default_view_slot_duration + ) { options.slotDuration = this.env.searchModel.context.calendar_slot_duration; } diff --git a/web_calendar_slot_duration/static/src/js/calendar_model.esm.js b/web_calendar_slot_duration/static/src/js/calendar_model.esm.js index 7acbbbaa0..b8c5bf5d3 100644 --- a/web_calendar_slot_duration/static/src/js/calendar_model.esm.js +++ b/web_calendar_slot_duration/static/src/js/calendar_model.esm.js @@ -17,7 +17,14 @@ patch(CalendarModel.prototype, "WebCalendarSlotDurationCalendarModel", { const [hours, minutes, seconds] = slot_duration .match(/(\d+):(\d+):(\d+)/) .slice(1, 4); - const durationFloat = hours + minutes / 60 + seconds / 3600; + // Convert all to float + // if we use a context like {'calendar_slot_duration': '01:30:00'} + // we will have on the backend a duration of 10 hour and 30 minutes + // instead of 1 hour and 30 minutes + const durationFloat = + parseFloat(hours) + + parseFloat(minutes) / 60 + + parseFloat(seconds) / 3600; partialRecord.end = partialRecord.start.plus({hours: durationFloat}); } return this._super(partialRecord, options);