[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@7af13089df
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
This commit is contained in:
Romeo Fragomeli
2020-03-31 15:09:18 +00:00
committed by Pierre Paridans
parent d57470387a
commit 7b815c3bf2
3 changed files with 63 additions and 14 deletions
@@ -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;
}
@@ -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,
});
@@ -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);