From 8f1ff119093e9ca9ff9080d37b1a75a227762269 Mon Sep 17 00:00:00 2001 From: Maryam Kia Date: Mon, 5 Feb 2024 16:15:17 +0100 Subject: [PATCH] [FIX] calendar: delete activity with event causes error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this PR: Canceling an activity linked to an event produces error because of non provided thread. Steps to reproduce: - Create an activity with event (call or meeting) in chatter - Try to cancel this activity - There is an error about undefined thread and activity remains on the chatter After this PR: - Thread is provided in `onUpdate` method to use in `load()` in chatter - `activityService` deletes the activity with event in `unlink` patch closes odoo/odoo#152737 Signed-off-by: Sébastien Theys (seb) --- .../static/src/activity/activity_patch.js | 4 ++- .../calendar/static/tests/activity_tests.js | 30 +++++++++++++++++++ .../mock_server/models/mail_activity.js | 23 +++++++++----- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/addons/calendar/static/src/activity/activity_patch.js b/addons/calendar/static/src/activity/activity_patch.js index 299800e00e7..ae55598342d 100644 --- a/addons/calendar/static/src/activity/activity_patch.js +++ b/addons/calendar/static/src/activity/activity_patch.js @@ -17,8 +17,10 @@ patch(Activity.prototype, { */ async unlink() { if (this.props.data.calendar_event_id) { + const thread = this.thread; + this.activityService.delete(this.props.data); await this.orm.call("mail.activity", "unlink_w_meeting", [[this.props.data.id]]); - this.props.onUpdate(); + this.props.onUpdate(thread); } else { super.unlink(); } diff --git a/addons/calendar/static/tests/activity_tests.js b/addons/calendar/static/tests/activity_tests.js index e0aed362b3d..75ccf2424b8 100644 --- a/addons/calendar/static/tests/activity_tests.js +++ b/addons/calendar/static/tests/activity_tests.js @@ -35,3 +35,33 @@ QUnit.test("activity click on Reschedule", async () => { await click(".btn", { text: "Reschedule" }); await contains(".o_calendar_view"); }); + +QUnit.test("Can cancel activity linked to an event", async () => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ name: "Milan Kundera" }); + const activityTypeId = pyEnv["mail.activity.type"].create({ + icon: "fa-calendar", + name: "Meeting", + }); + const attendeeId = pyEnv["calendar.attendee"].create({ + partner_id: partnerId, + }); + const calendaMeetingId = pyEnv["calendar.event"].create({ + res_model: "calendar.event", + name: "meeting1", + start: "2022-07-06 06:30:00", + attendee_ids: [attendeeId], + }); + pyEnv["mail.activity"].create({ + name: "Small Meeting", + activity_type_id: activityTypeId, + can_write: true, + res_id: partnerId, + res_model: "res.partner", + calendar_event_id: calendaMeetingId, + }); + const { openFormView } = await start(); + await openFormView("res.partner", partnerId); + await click(".o-mail-Activity .btn", { text: "Cancel" }); + await contains(".o-mail-Activity", { count: 0 }); +}); diff --git a/addons/calendar/static/tests/helpers/mock_server/models/mail_activity.js b/addons/calendar/static/tests/helpers/mock_server/models/mail_activity.js index b008c192c3c..950ba56fb0e 100644 --- a/addons/calendar/static/tests/helpers/mock_server/models/mail_activity.js +++ b/addons/calendar/static/tests/helpers/mock_server/models/mail_activity.js @@ -1,10 +1,10 @@ /** @odoo-module **/ // ensure mail override is applied first. -import '@mail/../tests/helpers/mock_server/models/mail_activity'; +import "@mail/../tests/helpers/mock_server/models/mail_activity"; import { patch } from "@web/core/utils/patch"; -import { MockServer } from '@web/../tests/helpers/mock_server'; +import { MockServer } from "@web/../tests/helpers/mock_server"; patch(MockServer.prototype, { //-------------------------------------------------------------------------- @@ -15,16 +15,23 @@ patch(MockServer.prototype, { * @override */ async _performRPC(route, args) { - if (args.model === 'mail.activity' && args.method === 'action_create_calendar_event') { + if (args.model === "mail.activity" && args.method === "action_create_calendar_event") { return { - type: 'ir.actions.act_window', + type: "ir.actions.act_window", name: "Meetings", - res_model: 'calendar.event', - view_mode: 'calendar', - views: [[false, 'calendar']], - target: 'current', + res_model: "calendar.event", + view_mode: "calendar", + views: [[false, "calendar"]], + target: "current", }; } + if (args.model === "mail.activity" && args.method === "unlink_w_meeting") { + const activities = this.getRecords("mail.activity", [["id", "in", args.args[0]]]); + const eventIds = activities.map((act) => act.calendar_event_id); + const res = this.mockUnlink("mail.activity", args.args[0]); + this.mockUnlink("calendar.event", eventIds); + return res; + } return super._performRPC(...arguments); }, });