diff options
| author | Tiffany Chang (tic) <tic@odoo.com> | 2019-12-31 10:37:16 +0000 |
|---|---|---|
| committer | Tiffany Chang (tic) <tic@odoo.com> | 2020-01-03 10:34:54 +0000 |
| commit | 3e37ec8844ee66b3898f8799be1765d080e0bfb4 (patch) | |
| tree | f3ac3b71d4abc9f3914242a8a5b7e7fa5e5f346d /addons | |
| parent | ae7f574e5446a7bc6c939fc273225b41e2296bf7 (diff) | |
[IMP] web: add 'create' attribute to calendar view
Previously it was always possible to create within the calendar view.
For some modules this did not make sense and lead to confusing behavior,
for example: a new model instance created in the calendar view that was
not viewable in the calendar view, but was viewable in other views. By
adding a 'create' attribute (to be used in view xml), we allow users to
choose whether or not they want a calendar view to be able to create.
Note that this change does not affect the edit ability of calendar views
for existing instances.
Part of
Task: 2126530
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/web/static/src/js/views/calendar/calendar_view.js | 2 | ||||
| -rw-r--r-- | addons/web/static/tests/views/calendar_tests.js | 96 |
2 files changed, 97 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/calendar/calendar_view.js b/addons/web/static/src/js/views/calendar/calendar_view.js index b1a6ea7be13..9c9355145ee 100644 --- a/addons/web/static/src/js/views/calendar/calendar_view.js +++ b/addons/web/static/src/js/views/calendar/calendar_view.js @@ -146,7 +146,7 @@ var CalendarView = AbstractView.extend({ this.loadParams.fields = fields; this.loadParams.fieldsInfo = viewInfo.fieldsInfo; this.loadParams.editable = !fields[mapping.date_start].readonly; - this.loadParams.creatable = true; + this.loadParams.creatable = this.controllerParams.activeActions.create; this.loadParams.eventLimit = eventLimit; this.loadParams.fieldColor = attrs.color; diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js index fb0a64b7705..0a3c31474e1 100644 --- a/addons/web/static/tests/views/calendar_tests.js +++ b/addons/web/static/tests/views/calendar_tests.js @@ -3078,6 +3078,102 @@ QUnit.module('Views', { calendar.destroy(); }); + + QUnit.test('edit record and attempt to create a record with "create" attribute set to false', async function (assert) { + assert.expect(8); + + var calendar = await createCalendarView({ + View: CalendarView, + model: 'event', + data: this.data, + arch: + '<calendar class="o_calendar_test" '+ + 'string="Events" '+ + 'event_open_popup="true" '+ + 'create="false" '+ + 'date_start="start" '+ + 'date_stop="stop" '+ + 'mode="month"/>', + archs: archs, + mockRPC: function (route, args) { + if (args.method === 'write') { + assert.deepEqual(args.args[1], {name: 'event 4 modified'}, "should update the record"); + } + return this._super.apply(this, arguments); + }, + viewOptions: { + initialDate: initialDate, + }, + }); + + // editing existing events should still be possible + // click on an existing event to open the formViewDialog + + await testUtils.dom.click(calendar.$('.fc-event:contains(event 4) .fc-content')); + + assert.ok(calendar.$('.o_cw_popover').length, "should open a popover clicking on event"); + assert.ok(calendar.$('.o_cw_popover .o_cw_popover_edit').length, "popover should have an edit button"); + assert.ok(calendar.$('.o_cw_popover .o_cw_popover_delete').length, "popover should have a delete button"); + assert.ok(calendar.$('.o_cw_popover .o_cw_popover_close').length, "popover should have a close button"); + + await testUtils.dom.click(calendar.$('.o_cw_popover .o_cw_popover_edit')); + + assert.ok($('.modal-body').length, "should open the form view in dialog when click on edit"); + + await testUtils.fields.editInput($('.modal-body input:first'), 'event 4 modified'); + await testUtils.dom.click($('.modal-footer button.btn:contains(Save)')); + + assert.notOk($('.modal-body').length, "save button should close the modal"); + + // creating an event should not be possible + // attempt to create a new event with create set to false + + var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); + + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); + await testUtils.nextTick(); + + assert.notOk($('.modal-sm').length, "shouldn't open a quick create dialog for creating a new event with create attribute set to false"); + + calendar.destroy(); + }); + + + QUnit.test('attempt to create record with "create" and "quick_add" attributes set to false', async function (assert) { + assert.expect(1); + + var calendar = await createCalendarView({ + View: CalendarView, + model: 'event', + data: this.data, + arch: + '<calendar class="o_calendar_test" '+ + 'string="Events" '+ + 'create="false" '+ + 'event_open_popup="true" '+ + 'quick_add="false" '+ + 'date_start="start" '+ + 'date_stop="stop" '+ + 'mode="month"/>', + archs: archs, + viewOptions: { + initialDate: initialDate, + }, + }); + + // attempt to create a new event with create set to false + + var $cell = calendar.$('.fc-day-grid .fc-row:eq(5) .fc-day:eq(2)'); + + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); + await testUtils.nextTick(); + + assert.strictEqual($('.modal').length, 0, "shouldn't open a form view for creating a new event with create attribute set to false"); + + calendar.destroy(); + }); }); }); |
