From d3fdbe29735727219dbfee627db9a96bfc7092cb Mon Sep 17 00:00:00 2001 From: qmo-odoo Date: Thu, 22 Apr 2021 12:11:22 +0000 Subject: [PATCH] [IMP] calendar,crm: improve mail.activities meetings management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, editing a mail.activity with the "meeting" category would open a modal form for the mail.activity, which did not make much sense. When editing a mail.activity that is linked to a calendar.event, you will now jump on the calendar view to edit the related event, which is much more convenient. In addition, when scheduling such an activity, the "Edit" button in the chatter is renamed to "Reschedule", to show the user that he will land on the calendar view. Furthermore, trying to delete an activity that is linked to a meeting will now prompt a confirmation dialog warning the user that the meeting will be deleted as well. Finally, we moved the 'phonecall' activity category from the 'voip' module (enterprise) to the base 'mail' module. Scheduling a phonecall activity will let the user choose if he wants to: - Simply save the activity, which will schedule a regular mail.activity - Open the calendar to create a related calendar.event Used typically when you want your colleagues to see that you are busy in your calendar during this call. Task-2486126 ENT PR odoo/enterprise#20431 UPG PR odoo/upgrade#2775 closes odoo/odoo#75530 Signed-off-by: Thibault Delavallee (tde) Co-authored-by: Aurélien Warnon --- addons/calendar/__manifest__.py | 3 + .../src/components/activity/activity.js | 35 +++++++++++ .../src/components/activity/activity.xml | 17 +++++ .../static/src/models/activity/activity.js | 63 +++++++++++++++++++ addons/calendar/views/mail_activity_views.xml | 12 ++-- addons/crm/data/mail_activity_demo.xml | 2 + addons/crm/models/__init__.py | 1 + addons/crm/models/mail_activity.py | 26 ++++++++ addons/mail/data/mail_activity_data.xml | 1 + addons/mail/models/mail_activity_type.py | 4 +- addons/mail/views/mail_activity_views.xml | 4 +- 11 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 addons/calendar/static/src/components/activity/activity.js create mode 100644 addons/calendar/static/src/components/activity/activity.xml create mode 100644 addons/calendar/static/src/models/activity/activity.js create mode 100644 addons/crm/models/mail_activity.py 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')]}