[IMP] web: do not pass default_name in calendar create if false

`name` field can be required and falsy `data.name` should not be
added as default in context or it warns for missing required field.

Task-2052536

closes odoo/odoo#35880

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Mohammed Shekha
2019-11-25 15:09:58 +00:00
committed by Alexandre Kühn
parent c349e306df
commit b7983df87a
2 changed files with 61 additions and 4 deletions
@@ -270,7 +270,11 @@ var CalendarController = AbstractController.extend({
var data = this.model.calendarEventToRecord(event.data);
var context = _.extend({}, this.context, event.options && event.options.context);
context.default_name = data.name || null;
// context default has more priority in default_get so if data.name is false then it may
// lead to error/warning while saving record in form view as name field can be required
if (data.name) {
context.default_name = data.name;
}
context['default_' + this.mapping.date_start] = data[this.mapping.date_start] || null;
if (this.mapping.date_stop) {
context['default_' + this.mapping.date_stop] = data[this.mapping.date_stop] || null;
@@ -571,7 +571,6 @@ QUnit.module('Views', {
mockRPC: function (route, args) {
if (args.method === "create") {
assert.deepEqual(args.kwargs.context, {
"default_name": null,
"default_start": "2016-12-13 06:00:00",
"default_stop": "2016-12-13 08:00:00",
"default_allday": null
@@ -1001,7 +1000,6 @@ QUnit.module('Views', {
mockRPC: function (route, args) {
if (args.method === "create") {
assert.deepEqual(args.kwargs.context, {
"default_name": null,
"default_start": "2016-12-13 06:00:00",
"default_stop": "2016-12-13 08:00:00",
"default_allday": null
@@ -1340,6 +1338,62 @@ QUnit.module('Views', {
calendar.destroy();
});
QUnit.test('create event with default context (no quickCreate)', async function (assert) {
assert.expect(3);
this.data.event.records = [];
const calendar = await createCalendarView({
View: CalendarView,
model: 'event',
data: this.data,
arch:
`<calendar
class="o_calendar_test"
date_start="start"
date_stop="stop"
mode="week"
quick_add="False"/>`,
archs,
viewOptions: {
initialDate: initialDate,
},
session: {
getTZOffset() {
return 120;
},
},
context: {
default_name: 'New',
},
intercepts: {
do_action(ev) {
assert.step('do_action');
assert.deepEqual(ev.data.action.context, {
default_name: "New",
default_start: "2016-12-14 05:00:00",
default_stop: "2016-12-15 17:00:00",
},
"should send the correct data to create events");
},
},
}, { positionalClicks: true });
var pos = calendar.$('.fc-bg td:eq(4)').offset();
try {
testUtils.dom.triggerPositionalMouseEvent(pos.left + 15, pos.top + 15, "mousedown");
} catch (e) {
calendar.destroy();
throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.');
}
pos = calendar.$('.fc-bg td:eq(5)').offset();
testUtils.dom.triggerPositionalMouseEvent(pos.left + 15, pos.top + 15, "mousemove");
testUtils.dom.triggerPositionalMouseEvent(pos.left + 15, pos.top + 15, "mouseup");
assert.verifySteps(['do_action']);
calendar.destroy();
});
QUnit.test('create all day event in week mode (no quickCreate)', async function (assert) {
assert.expect(1);
@@ -1367,7 +1421,6 @@ QUnit.module('Views', {
intercepts: {
do_action: function (event) {
assert.deepEqual(event.data.action.context, {
"default_name": null,
"default_start": "2016-12-14 05:00:00",
"default_stop": "2016-12-15 17:00:00",
},