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: + '', + 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: + '', + 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(); + }); }); }); diff --git a/doc/reference/views.rst b/doc/reference/views.rst index 1925ad3f07b..2a22bc6b13a 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -907,7 +907,9 @@ calendar view are: ``mode`` Default display mode when loading the calendar. Possible attributes are: ``day``, ``week``, ``month`` - +``create`` + allows *dis*\ abling the corresponding action in the view by setting the + corresponding attribute to ``false`` ```` declares fields to aggregate or to use in kanban *logic*. If the field is simply displayed in the calendar cards. diff --git a/odoo/addons/base/rng/calendar_view.rng b/odoo/addons/base/rng/calendar_view.rng index f073bab4bf1..3e122fd018d 100644 --- a/odoo/addons/base/rng/calendar_view.rng +++ b/odoo/addons/base/rng/calendar_view.rng @@ -22,6 +22,7 @@ +