summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomeo Fragomeli <rfr@odoo.com>2020-03-18 09:19:05 +0000
committerPierre Paridans <app@odoo.com>2020-03-31 15:09:18 +0000
commit7b815c3bf28db3625c4d377eab6aec90867825be (patch)
treee7a99087f2f11218504e5ccac82f47d9a3c9d64c
parentd57470387aa1a155e004aaebec7b8b66de581dcd (diff)
[FIX] web: calendar's drag-and-dropped event has wrong end-date
Due to previous commit, in month view, the flag marking events as "all day" is no more present and so some logic is not applied anymore. This results into the wrong end-date. With this commit we avoid to change the end date of an event in FullCalendar. Note that it changes the behavior on drag-and-dropped event in month view: * Before both the last and this commit, an event if 1H will become an "all day" event when it's dropped into another cell. * After them, the time will be the same as the original event and only the date will change. Also, one test was already added in commit odoo/odoo@7af13089dffcd3c9d98716af4aa76b923825fdfc to check that, in month view, when we move a non-"all day" event to another day, it can't change into a all day event. This commit adds a second test to cover the case when the "all day" mapping is present. Task ID: 2183249
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_model.js15
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_renderer.js1
-rw-r--r--addons/web/static/tests/views/calendar_tests.js61
3 files changed, 63 insertions, 14 deletions
diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js
index caa1d26e8c6..20c067d2ccc 100644
--- a/addons/web/static/src/js/views/calendar/calendar_model.js
+++ b/addons/web/static/src/js/views/calendar/calendar_model.js
@@ -94,7 +94,7 @@ return AbstractModel.extend({
if (this.mapping.all_day) {
if (event.record) {
data[this.mapping.all_day] =
- (this.scale !== 'month' && event.allDay) ||
+ (this.data.scale !== 'month' && event.allDay) ||
event.record[this.mapping.all_day] &&
end.diff(start) < 10 ||
false;
@@ -758,18 +758,7 @@ return AbstractModel.extend({
'attendees':attendees,
};
- if (this.mapping.all_day && evt[this.mapping.all_day]) {
- // r.start = date_start.format('YYYY-MM-DD');
- // r.end = date_stop.format('YYYY-MM-DD');
- } else if (this.data.scale === 'month' && this.fields[this.mapping.date_start].type !== 'date') {
- // In month, FullCalendar gives the end day as the
- // next day at midnight (instead of 23h59).
- date_stop.add(1, 'days');
-
- // allow to resize in month mode
- r.reset_allday = r.allDay;
- r.start = date_start.toDate();
- r.end = date_stop.startOf('day').toDate();
+ if (!(this.mapping.all_day && evt[this.mapping.all_day]) && this.data.scale === 'month' && this.fields[this.mapping.date_start].type !== 'date') {
r.showTime = true;
}
diff --git a/addons/web/static/src/js/views/calendar/calendar_renderer.js b/addons/web/static/src/js/views/calendar/calendar_renderer.js
index f6ae085e81a..4f492585ef1 100644
--- a/addons/web/static/src/js/views/calendar/calendar_renderer.js
+++ b/addons/web/static/src/js/views/calendar/calendar_renderer.js
@@ -338,7 +338,6 @@ return AbstractRenderer.extend({
event = Object.assign({}, event, {
r_start: fc4Event.extendedProps.r_start && moment(fc4Event.extendedProps.r_start).utcOffset(0, true),
r_end: fc4Event.extendedProps.r_end && moment(fc4Event.extendedProps.r_end).utcOffset(0, true),
- reset_allday: fc4Event.extendedProps.reset_allday,
record: fc4Event.extendedProps.record,
attendees: fc4Event.extendedProps.attendees,
});
diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js
index b6debe56f58..0de9c8e09dc 100644
--- a/addons/web/static/tests/views/calendar_tests.js
+++ b/addons/web/static/tests/views/calendar_tests.js
@@ -2857,6 +2857,67 @@ QUnit.module('Views', {
calendar.destroy();
});
+ QUnit.test("drag and drop on month mode with all_day mapping", async function (assert) {
+ // Same test as before but in calendarEventToRecord (calendar_model.js) there is
+ // different condition branching with all_day mapping or not
+ assert.expect(2);
+
+ const calendar = await createCalendarView({
+ arch:
+ `<calendar date_start="start" date_stop="stop" mode="month" event_open_popup="true" quick_add="False" all_day="allday">
+ <field name="name"/>
+ <field name="partner_id"/>
+ </calendar>`,
+ archs: archs,
+ data: this.data,
+ model: 'event',
+ View: CalendarView,
+ viewOptions: { initialDate: initialDate },
+ });
+
+ // Create event (on 20 december)
+ var $cell = calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day:eq(2)');
+ testUtils.triggerMouseEvent($cell, "mousedown");
+ testUtils.triggerMouseEvent($cell, "mouseup");
+ await testUtils.nextTick();
+ var $input = $('.modal-body input:first');
+ await testUtils.fields.editInput($input, "An event");
+ await testUtils.dom.click($('.o_field_widget[name="allday"] input'));
+ await testUtils.nextTick();
+
+ // use datepicker to enter a date: 12/20/2016 07:00:00
+ testUtils.dom.openDatepicker($('.o_field_widget[name="start"].o_datepicker'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch a[data-action="togglePicker"]'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker .timepicker-hour'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-hours td.hour:contains(07)'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch a[data-action="close"]'));
+
+ // use datepicker to enter a date: 12/20/2016 19:00:00
+ testUtils.dom.openDatepicker($('.o_field_widget[name="stop"].o_datepicker'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch a[data-action="togglePicker"]'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker .timepicker-hour'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .timepicker-hours td.hour:contains(19)'));
+ await testUtils.dom.click($('.bootstrap-datetimepicker-widget .picker-switch a[data-action="close"]'));
+
+ await testUtils.dom.click($('.modal button.btn-primary'));
+ await testUtils.nextTick();
+
+ // Move event to another day (on 19 december)
+ await testUtils.dragAndDrop(
+ calendar.$('.fc-event:contains("An event")'),
+ calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day-top:eq(1)')
+ );
+ await testUtils.nextTick();
+ await testUtils.dom.click(calendar.$('.fc-event:contains("An event")'));
+
+ assert.containsOnce(calendar, '.popover:contains("07:00")',
+ "start hour shouldn't have been changed");
+ assert.containsOnce(calendar, '.popover:contains("19:00")',
+ "end hour shouldn't have been changed");
+
+ calendar.destroy();
+ });
+
QUnit.test('drag and drop on month mode with date_start and date_delay', async function (assert) {
assert.expect(1);