From d8d30829c688bfea0a17f429f05986bb86d24bd3 Mon Sep 17 00:00:00 2001 From: Dharmraj Jhala Date: Tue, 5 Jul 2022 10:37:49 +0000 Subject: [PATCH] [FIX] calendar: open calendar view from 'Reschedule' activity button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With recent commit[1], we now use the wowlEnv instead of the legacy one, and use the service provided by env to call the rpc. This was adapted in the activity model, but not on the patched method under calendar. This commit fixes the issues to adpat the change, and so the 'Reschedule' button for the meeting activity now opens the calendar view as expected. Apart from that, this commit also tries to align this button with other activity buttons, for better UI. commit[1] - https://github.com/odoo/odoo/commit/3573a7fef497d taskID-2899402 closes odoo/odoo#95747 X-original-commit: b7efe2a80f9da175114cf1138565580981690001 Signed-off-by: Sébastien Theys (seb) --- .../src/components/activity/activity.xml | 2 +- addons/calendar/static/src/models/activity.js | 4 +- .../calendar/static/tests/activity_tests.js | 49 +++++++++++++++++++ .../static/tests/helpers/mock_server.js | 26 ++++++++++ .../tests/helpers/view_definitions_setup.js | 8 +++ 5 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 addons/calendar/static/tests/activity_tests.js create mode 100644 addons/calendar/static/tests/helpers/view_definitions_setup.js diff --git a/addons/calendar/static/src/components/activity/activity.xml b/addons/calendar/static/src/components/activity/activity.xml index 52377809d24..11e0b9c8c07 100644 --- a/addons/calendar/static/src/components/activity/activity.xml +++ b/addons/calendar/static/src/components/activity/activity.xml @@ -7,7 +7,7 @@ - diff --git a/addons/calendar/static/src/models/activity.js b/addons/calendar/static/src/models/activity.js index b741e311329..80d706ee25d 100644 --- a/addons/calendar/static/src/models/activity.js +++ b/addons/calendar/static/src/models/activity.js @@ -55,9 +55,7 @@ patchRecordMethods('Activity', { method: 'action_create_calendar_event', args: [[this.id]], }); - this.env.bus.trigger('do-action', { - action - }); + this.env.services.action.doAction(action); } }, }); diff --git a/addons/calendar/static/tests/activity_tests.js b/addons/calendar/static/tests/activity_tests.js new file mode 100644 index 00000000000..bd5bd01761f --- /dev/null +++ b/addons/calendar/static/tests/activity_tests.js @@ -0,0 +1,49 @@ +/** @odoo-module **/ + +import { start, startServer } from '@mail/../tests/helpers/test_utils'; + +QUnit.module('calendar', () => { +QUnit.module('components', () => { +QUnit.module('activity_tests.js'); + +QUnit.test('activity click on Reschedule', async function (assert) { + assert.expect(1); + + const pyEnv = await startServer(); + const resPartnerId = pyEnv['res.partner'].create({}); + const meetingActivityTypeId = pyEnv['mail.activity.type'].create({ icon: 'fa-calendar', name: "Meeting" }); + const calendarAttendeeId = pyEnv['calendar.attendee'].create({ partner_id: resPartnerId }); + const calendaMeetingId = pyEnv['calendar.event'].create({ + res_model: "calendar.event", + name: "meeting1", + start: "2022-07-06 06:30:00", + attendee_ids: [calendarAttendeeId], + }); + pyEnv['mail.activity'].create({ + name: "Small Meeting", + activity_type_id: meetingActivityTypeId, + can_write: true, + res_id: resPartnerId, + res_model: 'res.partner', + calendar_event_id: calendaMeetingId, + }); + + const { click, openFormView } = await start(); + + await openFormView( + { + res_model: 'res.partner', + res_id: resPartnerId, + }, + ); + + await click('.o_Activity_editButton'); + assert.containsOnce( + document.body, + '.o_calendar_view', + "should have opened calendar view" + ); +}); + +}); +}); diff --git a/addons/calendar/static/tests/helpers/mock_server.js b/addons/calendar/static/tests/helpers/mock_server.js index 3e6be594327..b2650358fb2 100644 --- a/addons/calendar/static/tests/helpers/mock_server.js +++ b/addons/calendar/static/tests/helpers/mock_server.js @@ -9,6 +9,32 @@ import { MockServer } from '@web/../tests/helpers/mock_server'; import { datetime_to_str } from 'web.time'; patch(MockServer.prototype, 'calendar', { + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + async _performRPC(route, args) { + // mail.activity methods + if (args.model === 'mail.activity' && args.method === 'action_create_calendar_event') { + return { + type: 'ir.actions.act_window', + name: "Meetings", + res_model: 'calendar.event', + view_mode: 'calendar', + views: [[false, 'calendar']], + target: 'current', + }; + } + // calendar.event methods + if (args.model === 'calendar.event' && args.method === 'check_access_rights') { + return true; + } + return this._super(...arguments); + }, + //-------------------------------------------------------------------------- // Private Mocked Methods //-------------------------------------------------------------------------- diff --git a/addons/calendar/static/tests/helpers/view_definitions_setup.js b/addons/calendar/static/tests/helpers/view_definitions_setup.js new file mode 100644 index 00000000000..ab6e8237cee --- /dev/null +++ b/addons/calendar/static/tests/helpers/view_definitions_setup.js @@ -0,0 +1,8 @@ +/** @odoo-module **/ + +import { registry } from '@web/core/registry'; + +const viewArchsRegistry = registry.category('mail.view.archs'); +const calendarArchsRegistry = viewArchsRegistry.category('calendar'); + +calendarArchsRegistry.add('default', '');