[FIX] web: month view drop

- Install the 'Maintenance' app
- Create a maintenance request, set a day and a duration of 6 hours
- Go the calendar view, month mode
- Move the maintenance request from one day to another

The duration is changed with a non-sense value.

In month mode, the hours are not represented in the calendar so it is
not possible to compute the `date_delay`. Moreover, when a record is
moved from one date to another (`_onDropRecord`) in month mode, there is
actually no point recomputing the duration; the `date_start` is enough.

Note that `date_delay` is used (at the time of writing) in 2 views and
absolutely not tested.

opw-1984637

closes odoo/odoo#33193

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-05-06 15:59:13 +00:00
parent 6368971ba0
commit d809b47681
3 changed files with 50 additions and 2 deletions
@@ -204,7 +204,9 @@ var CalendarController = AbstractController.extend({
* @param {OdooEvent} event
*/
_onDropRecord: function (event) {
this._updateRecord(event.data);
this._updateRecord(_.extend({}, event.data, {
'drop': true,
}));
},
/**
* @private
@@ -105,7 +105,9 @@ return AbstractModel.extend({
}
if (this.mapping.date_delay) {
data[this.mapping.date_delay] = (end.diff(start) <= 0 ? end.endOf('day').diff(start) : end.diff(start)) / 1000 / 3600;
if (this.data.scale !== 'month' || (this.data.scale === 'month' && !event.drop)) {
data[this.mapping.date_delay] = (end.diff(start) <= 0 ? end.endOf('day').diff(start) : end.diff(start)) / 1000 / 3600;
}
}
return data;
@@ -44,6 +44,7 @@ QUnit.module('Views', {
stop_date: {string: "stop date", type: "date"},
start: {string: "start datetime", type: "datetime"},
stop: {string: "stop datetime", type: "datetime"},
delay: {string: "delay", type: "float"},
allday: {string: "allday", type: "boolean"},
partner_ids: {string: "attendees", type: "one2many", relation: 'partner', default: [[6, 0, [1]]]},
type: {string: "type", type: "integer"},
@@ -2393,6 +2394,49 @@ QUnit.module('Views', {
calendar.destroy();
});
QUnit.test('drag and drop on month mode with date_start and date_delay', function (assert) {
assert.expect(1);
var calendar = createView({
View: CalendarView,
model: 'event',
data: this.data,
arch:
'<calendar date_start="start" date_delay="delay" mode="month">'+
'<field name="name"/>'+
'<field name="start"/>'+
'<field name="delay"/>'+
'</calendar>',
archs: archs,
viewOptions: {
initialDate: initialDate,
},
mockRPC: function (route, args) {
if (args.method === "write") {
// delay should not be written at drag and drop
assert.equal(args.args[1].delay, undefined)
}
return this._super(route, args);
},
});
// 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");
var $input = $('.modal-body input:first');
$input.val("An event").trigger('input');
$('.modal button.btn:contains(Create)').trigger('click');
// Move event to another day (on 27 november)
testUtils.dragAndDrop(
calendar.$('.fc-event').first(),
calendar.$('.fc-day-top').first()
);
calendar.destroy();
});
QUnit.test('form_view_id attribute works (for creating events)', function (assert) {
assert.expect(1);