[FIX] web: drag & drop month calendar->keep time
In fullcalendar, we have in f5b7ad80f fake moments date with UTC time
that are the local time, thus when we move an event to another day, we
need to set it as:
- the selected year-month-day
- the original utc hours (real local hours) -> local hours
- the original utc minutes (real local minutes) -> local minutes
- the original utc seconds (real local seconds) -> local seconds
When it is sent to server, timezone offset will be removed so we will
transfer to server the expected datetime in UTC.
With this changeset we send server the correct time when a fullcalendar
event is "all_day" but the original event was not (eg. drag and dropping
event on the month view).
Added test without change failed with:
- 4. event moved to 27th nov 16h00 +40 hours timezone
(expected "2016-11-29 08:00:00", result: "2016-11-27 16:00:00")
- 5. expected: "event|6|11/27/2016|16:00:00"
result: "event|1|12/09/2016|08:00:00"
- 6. expected: "event|1|12/09/2016|08:00:00"
result: "event|3|12/10/2016|23:55:05"
opw-1955281
closes #32136
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
@@ -73,9 +73,11 @@ return AbstractModel.extend({
|
||||
.utc();
|
||||
} else {
|
||||
// default hours in the user's timezone
|
||||
start.hours(7).add(-this.getSession().getTZOffset(start), 'minutes');
|
||||
end.hours(19).add(-this.getSession().getTZOffset(end), 'minutes');
|
||||
start.hours(7);
|
||||
end.hours(19);
|
||||
}
|
||||
start.add(-this.getSession().getTZOffset(start), 'minutes');
|
||||
end.add(-this.getSession().getTZOffset(end), 'minutes');
|
||||
}
|
||||
} else {
|
||||
start.add(-this.getSession().getTZOffset(start), 'minutes');
|
||||
|
||||
@@ -2053,6 +2053,60 @@ QUnit.module('Views', {
|
||||
calendar.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('timezone does not affect drag and drop', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
var calendar = createView({
|
||||
View: CalendarView,
|
||||
model: 'event',
|
||||
data: this.data,
|
||||
arch:
|
||||
'<calendar date_start="start" mode="month">'+
|
||||
'<field name="name"/>'+
|
||||
'<field name="start"/>'+
|
||||
'</calendar>',
|
||||
archs: archs,
|
||||
viewOptions: {
|
||||
initialDate: initialDate,
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "write") {
|
||||
assert.deepEqual(args.args[0], [6], "event 6 is moved")
|
||||
assert.deepEqual(args.args[1].start, "2016-11-29 08:00:00",
|
||||
"event moved to 27th nov 16h00 +40 hours timezone")
|
||||
}
|
||||
return this._super(route, args);
|
||||
},
|
||||
session: {
|
||||
getTZOffset: function () {
|
||||
return -2400; // 40 hours timezone
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
var events = calendar.$('.fc-event').map(function () {
|
||||
return $(this).text().trim().replace(/\s+/g, '|');
|
||||
});
|
||||
|
||||
assert.strictEqual(events[0], "event|1|12/09/2016|08:00:00");
|
||||
assert.strictEqual(events[5], "event|6|12/16/2016|16:00:00");
|
||||
|
||||
// Move event 6 as on first day of month view (27th november 2016)
|
||||
testUtils.dragAndDrop(
|
||||
calendar.$('.fc-event').eq(5),
|
||||
calendar.$('.fc-day-top').first()
|
||||
);
|
||||
|
||||
var events = calendar.$('.fc-event').map(function () {
|
||||
return $(this).text().trim().replace(/\s+/g, '|');
|
||||
});
|
||||
|
||||
assert.strictEqual(events[0], "event|6|11/27/2016|16:00:00");
|
||||
assert.strictEqual(events[1], "event|1|12/09/2016|08:00:00");
|
||||
|
||||
calendar.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('form_view_id attribute works (for creating events)', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user