[FIX] calendar: delete activity with event causes error
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) <seb@odoo.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user