diff --git a/addons/calendar/__manifest__.py b/addons/calendar/__manifest__.py index 11fb1122dc2..410b6400c6f 100644 --- a/addons/calendar/__manifest__.py +++ b/addons/calendar/__manifest__.py @@ -39,6 +39,8 @@ If you need to manage your meetings, you should install the CRM module. 'auto_install': False, 'assets': { 'web.assets_backend': [ + 'calendar/static/src/models/activity/activity.js', + 'calendar/static/src/components/activity/activity.js', 'calendar/static/src/scss/calendar.scss', 'calendar/static/src/js/base_calendar.js', 'calendar/static/src/js/calendar_renderer.js', @@ -53,6 +55,7 @@ If you need to manage your meetings, you should install the CRM module. ], 'web.assets_qweb': [ 'calendar/static/src/xml/base_calendar.xml', + 'calendar/static/src/components/activity/activity.xml', ], }, 'license': 'LGPL-3', diff --git a/addons/calendar/static/src/components/activity/activity.js b/addons/calendar/static/src/components/activity/activity.js new file mode 100644 index 00000000000..a49260c49f4 --- /dev/null +++ b/addons/calendar/static/src/components/activity/activity.js @@ -0,0 +1,35 @@ +/** @odoo-module */ + +import { Activity } from '@mail/components/activity/activity'; +import { patch } from 'web.utils'; +import Dialog from 'web.Dialog'; +import core from 'web.core'; +const _t = core._t; + +patch(Activity.prototype, 'calendar/static/src/components/activity/activity.js', { + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Small override that asks for confirmation in case there is a meeting linked to this activity. + * + * @override + */ + _onClickCancel(ev) { + const superMethod = this._super; + if (!this.activity.calendar_event_id){ + this._super(ev); + } else { + Dialog.confirm( + this, + _t("The activity is linked to a meeting. Deleting it will remove the meeting as well. Do you want to proceed ?"), { + confirm_callback: function () { + superMethod(ev); + }, + } + ); + } + } + +}); diff --git a/addons/calendar/static/src/components/activity/activity.xml b/addons/calendar/static/src/components/activity/activity.xml new file mode 100644 index 00000000000..5cffc8e2415 --- /dev/null +++ b/addons/calendar/static/src/components/activity/activity.xml @@ -0,0 +1,17 @@ + + + + + + !activity.calendar_event_id + + + + + + + + + diff --git a/addons/calendar/static/src/models/activity/activity.js b/addons/calendar/static/src/models/activity/activity.js new file mode 100644 index 00000000000..7dbb4dfbf36 --- /dev/null +++ b/addons/calendar/static/src/models/activity/activity.js @@ -0,0 +1,63 @@ +/** @odoo-module **/ + +import { + registerClassPatchModel, + registerInstancePatchModel, + registerFieldPatchModel +} from'@mail/model/model_core'; +import { attr } from '@mail/model/model_field'; + +registerFieldPatchModel('mail.activity', 'calendar/static/src/models/activity/activity.js', { + calendar_event_id: attr({ default: false }), +}); + +registerClassPatchModel('mail.activity', 'calendar/static/src/models/activity/activity.js', { + /** + * @override + */ + convertData(data) { + const res = this._super(data); + if ('calendar_event_id' in data) { + res.calendar_event_id = data.calendar_event_id[0]; + } + return res; + }, +}); + +registerInstancePatchModel('mail.activity', 'calendar/static/src/models/activity/activity.js', { + /** + * @override + */ + async deleteServerRecord() { + if (!this.calendar_event_id){ + await this._super(); + } else { + await this.async(() => this.env.services.rpc({ + model: 'mail.activity', + method: 'unlink_w_meeting', + args: [[this.id]], + })); + this.delete(); + } + }, + + /** + * In case the activity is linked to a meeting, we want to open the calendar view instead. + * + * @override + */ + async edit() { + if (!this.calendar_event_id){ + this._super(); + } else { + const action = await this.async(() => this.env.services.rpc({ + model: 'mail.activity', + method: 'action_create_calendar_event', + args: [[this.id]], + })); + this.env.bus.trigger('do-action', { + action + }); + } + } +}); diff --git a/addons/calendar/views/mail_activity_views.xml b/addons/calendar/views/mail_activity_views.xml index d3681be20b1..a434a4943a4 100644 --- a/addons/calendar/views/mail_activity_views.xml +++ b/addons/calendar/views/mail_activity_views.xml @@ -12,21 +12,21 @@ {'invisible': [('activity_category', '=', 'meeting')]} - - {'invisible': ['|', ('activity_category', '=', 'meeting'), ('id', '!=', False)]} + + {'invisible': ['|', ('activity_category', 'in', ['meeting', 'phonecall']), ('id', '!=', False)]} + + + {'invisible': [('activity_category', '!=', 'phonecall'), ('id', '=', False)]} {'invisible': ['|', ('activity_category', '=', 'meeting'), ('chaining_type', '=', 'trigger')]} - - {'invisible': [('activity_category', '=', 'meeting')]} - {'invisible': [('activity_category', '=', 'meeting')]}