diff options
| author | jbm-odoo <jbm@odoo.com> | 2020-09-04 09:16:35 +0000 |
|---|---|---|
| committer | jbm-odoo <jbm@odoo.com> | 2020-09-16 12:48:50 +0000 |
| commit | 255eb91dd5e9fb39a7625064d1ba8e0b492bfb85 (patch) | |
| tree | 7dd2d8a50e037a04763e62f6f20d6526b44a7a7a | |
| parent | a677859a03c86bf6ac791c31f52ce8609bcba594 (diff) | |
[FIX] microsoft_calendar: Badge when sync is active
Add a cron to sync events in Microsoft calendar
In Google and Microsoft calendar: remove 'sync with ...' button
when the synchronization is already activated, and replace it by a
badge.
closes odoo/odoo#57076
Taskid: 2329313
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
12 files changed, 108 insertions, 24 deletions
diff --git a/addons/base_setup/models/res_config_settings.py b/addons/base_setup/models/res_config_settings.py index acbe5a873c5..70bf35c0bcd 100644 --- a/addons/base_setup/models/res_config_settings.py +++ b/addons/base_setup/models/res_config_settings.py @@ -20,7 +20,7 @@ class ResConfigSettings(models.TransientModel): module_google_calendar = fields.Boolean( string='Allow the users to synchronize their calendar with Google Calendar') module_microsoft_calendar = fields.Boolean( - string='Allow the users to synchronize their calendar with Office 365 Calendar') + string='Allow the users to synchronize their calendar with Outlook Calendar') module_google_drive = fields.Boolean("Attach Google documents to any record") module_google_spreadsheet = fields.Boolean("Google Spreadsheet") module_auth_oauth = fields.Boolean("Use external authentication providers (OAuth)") diff --git a/addons/base_setup/views/res_config_settings_views.xml b/addons/base_setup/views/res_config_settings_views.xml index 7398104b97f..b2c9a48f4cc 100644 --- a/addons/base_setup/views/res_config_settings_views.xml +++ b/addons/base_setup/views/res_config_settings_views.xml @@ -253,7 +253,7 @@ <field name="module_microsoft_calendar" /> </div> <div class="o_setting_right_pane"> - <label string="Office 365 Calendar" for="module_microsoft_calendar"/> + <label string="Outlook Calendar" for="module_microsoft_calendar"/> <div class="text-muted"> Synchronize your calendar with Outlook </div> diff --git a/addons/google_calendar/static/src/js/google_calendar.js b/addons/google_calendar/static/src/js/google_calendar.js index b19bafea384..c7157aa359e 100644 --- a/addons/google_calendar/static/src/js/google_calendar.js +++ b/addons/google_calendar/static/src/js/google_calendar.js @@ -16,6 +16,24 @@ const GoogleCalendarModel = CalendarModel.include({ /** * @override + */ + init: function () { + this._super.apply(this, arguments); + this.google_is_sync = true; + }, + + /** + * @override + */ + __get: function () { + var result = this._super.apply(this, arguments); + result.google_is_sync = this.google_is_sync; + return result; + }, + + + /** + * @override * @returns {Promise} */ async _loadCalendar() { @@ -35,6 +53,7 @@ const GoogleCalendarModel = CalendarModel.include({ }, _syncGoogleCalendar(shadow = false) { + var self = this; var context = this.getSession().user_context; return this._rpc({ route: '/google_calendar/sync_data', @@ -43,7 +62,14 @@ const GoogleCalendarModel = CalendarModel.include({ fromurl: window.location.href, local_context: context, // LUL TODO remove this local_context } - }, {shadow}); + }, {shadow}).then(function (result) { + if (result.status === "need_config_from_admin" || result.status === "need_auth") { + self.google_is_sync = false; + } else if (result.status === "no_new_event_from_google" || result.status === "need_refresh") { + self.google_is_sync = true; + } + return result + }); }, }) @@ -115,12 +141,16 @@ const GoogleCalendarRenderer = CalendarRenderer.include({ this._super.apply(this, arguments); this.$googleButton = $(); if (this.model === "calendar.event") { - this.$googleButton = $('<button/>', {type: 'button', html: _t("Sync with <b>Google</b>")}) + if (this.state.google_is_sync) { + this.$googleButton = $('<span/>', {html: _t("Synched with Google")}) + .addClass('o_google_sync badge badge-pill badge-success') + .prepend($('<i/>', {class: "fa mr-2 fa-check"})) + .appendTo(self.$sidebar); + } else { + this.$googleButton = $('<button/>', {type: 'button', html: _t("Sync with <b>Google</b>")}) .addClass('o_google_sync_button oe_button btn btn-secondary') - .prepend($('<img/>', { - src: "/google_calendar/static/src/img/calendar_32.png", - })) .appendTo(self.$sidebar); + } } }, diff --git a/addons/google_calendar/static/src/scss/google_calendar.scss b/addons/google_calendar/static/src/scss/google_calendar.scss index 1ee8feef473..54b5c82655f 100644 --- a/addons/google_calendar/static/src/scss/google_calendar.scss +++ b/addons/google_calendar/static/src/scss/google_calendar.scss @@ -1,10 +1,12 @@ .o_google_sync_button { - display: block; margin: auto; > img { margin-right: 10px; } } +.o_google_sync.badge { + border: none; +} img.calendar_img_tuto { margin: 0 0 10px 50px; diff --git a/addons/google_calendar/static/tests/google_calendar_tests.js b/addons/google_calendar/static/tests/google_calendar_tests.js index 5ec1e475af5..db98e22929f 100644 --- a/addons/google_calendar/static/tests/google_calendar_tests.js +++ b/addons/google_calendar/static/tests/google_calendar_tests.js @@ -70,7 +70,7 @@ QUnit.module('Google Calendar', { }, function () { QUnit.test('sync google calendar', async function (assert) { - assert.expect(8); + assert.expect(9); var calendar = await createCalendarView({ View: GoogleCalendarView, @@ -105,12 +105,14 @@ QUnit.module('Google Calendar', { assert.containsN(calendar, '.fc-event', 3, "should display 3 events on the month"); - await testUtils.dom.click(calendar.$('.o_google_sync_button')); + await testUtils.dom.click(calendar.$('.o_calendar_button_next')); + await testUtils.dom.click(calendar.$('.o_calendar_button_prev')); assert.verifySteps([ '/google_calendar/sync_data', '/web/dataset/call_kw/calendar.event/search_read', '/google_calendar/sync_data', + '/web/dataset/call_kw/calendar.event/search_read', '/google_calendar/sync_data', '/web/dataset/call_kw/calendar.event/search_read', ], 'should do a search_read before and after the call to sync_data'); diff --git a/addons/microsoft_calendar/__manifest__.py b/addons/microsoft_calendar/__manifest__.py index 763a1088803..03dd4d1fb56 100644 --- a/addons/microsoft_calendar/__manifest__.py +++ b/addons/microsoft_calendar/__manifest__.py @@ -9,6 +9,7 @@ 'depends': ['microsoft_account', 'calendar'], 'qweb': ['static/src/xml/*.xml'], 'data': [ + 'data/microsoft_calendar_data.xml', 'security/ir.model.access.csv', 'wizard/reset_account_views.xml', 'views/res_config_settings_views.xml', diff --git a/addons/microsoft_calendar/data/microsoft_calendar_data.xml b/addons/microsoft_calendar/data/microsoft_calendar_data.xml new file mode 100644 index 00000000000..f41a1d38316 --- /dev/null +++ b/addons/microsoft_calendar/data/microsoft_calendar_data.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<odoo> + <data> + <record forcecreate="True" id="ir_cron_sync_all_cals" model="ir.cron"> + <field name="name">Outlook: synchronization</field> + <field name="model_id" ref="model_res_users"/> + <field name="state">code</field> + <field name="code"> +model._sync_all_microsoft_calendar() + </field> + <field name="user_id" ref="base.user_root" /> + <field name="interval_number">12</field> + <field name="interval_type">hours</field> + <field name="numbercall">-1</field> + <field eval="False" name="doall" /> + </record> + </data> +</odoo> diff --git a/addons/microsoft_calendar/models/microsoft_sync.py b/addons/microsoft_calendar/models/microsoft_sync.py index 888fe09eff0..ea91094bff8 100644 --- a/addons/microsoft_calendar/models/microsoft_sync.py +++ b/addons/microsoft_calendar/models/microsoft_sync.py @@ -112,7 +112,7 @@ class MicrosoftSync(models.AbstractModel): synced.write({self._active_name: False}) self = self - synced elif synced: - raise UserError(_("You cannot delete a record synchronized with Microsoft Calendar, archive it instead.")) + raise UserError(_("You cannot delete a record synchronized with Outlook Calendar, archive it instead.")) return super().unlink() @api.model diff --git a/addons/microsoft_calendar/models/res_users.py b/addons/microsoft_calendar/models/res_users.py index 7354ea45f44..dec51d171de 100644 --- a/addons/microsoft_calendar/models/res_users.py +++ b/addons/microsoft_calendar/models/res_users.py @@ -39,7 +39,7 @@ class User(models.Model): client_secret = get_param('microsoft_calendar_client_secret') if not client_id or not client_secret: - raise UserError(_("The account for the Microsoft Calendar service is not configured.")) + raise UserError(_("The account for the Outlook Calendar service is not configured.")) headers = {"content-type": "application/x-www-form-urlencoded"} data = { diff --git a/addons/microsoft_calendar/static/src/js/microsoft_calendar.js b/addons/microsoft_calendar/static/src/js/microsoft_calendar.js index 41ad9e23675..289ba848b47 100644 --- a/addons/microsoft_calendar/static/src/js/microsoft_calendar.js +++ b/addons/microsoft_calendar/static/src/js/microsoft_calendar.js @@ -16,6 +16,23 @@ const MicrosoftCalendarModel = CalendarModel.include({ /** * @override + */ + init: function () { + this._super.apply(this, arguments); + this.microsoft_is_sync = true; + }, + + /** + * @override + */ + __get: function () { + var result = this._super.apply(this, arguments); + result.microsoft_is_sync = this.microsoft_is_sync; + return result; + }, + + /** + * @override * @returns {Promise} */ async _loadCalendar() { @@ -29,19 +46,27 @@ const MicrosoftCalendarModel = CalendarModel.include({ if (error.event) { error.event.preventDefault(); } - console.error("Could not synchronize Microsoft events now.", error); + console.error("Could not synchronize Outlook events now.", error); } return _super(...arguments); }, _syncMicrosoftCalendar(shadow = false) { + var self = this; return this._rpc({ route: '/microsoft_calendar/sync_data', params: { model: this.modelName, fromurl: window.location.href, } - }, {shadow}); + }, {shadow}).then(function (result) { + if (result.status === "need_config_from_admin" || result.status === "need_auth") { + self.microsoft_is_sync = false; + } else if (result.status === "no_new_event_from_microsoft" || result.status === "need_refresh") { + self.microsoft_is_sync = true; + } + return result + }); }, }); @@ -68,7 +93,7 @@ const MicrosoftCalendarController = CalendarController.include({ return this.model._syncMicrosoftCalendar().then(function (o) { if (o.status === "need_auth") { - Dialog.alert(self, _t("You will be redirected to Microsoft to authorize the access to your calendar."), { + Dialog.alert(self, _t("You will be redirected to Outlook to authorize the access to your calendar."), { confirm_callback: function() { framework.redirect(o.url); }, @@ -76,14 +101,14 @@ const MicrosoftCalendarController = CalendarController.include({ }); } else if (o.status === "need_config_from_admin") { if (!_.isUndefined(o.action) && parseInt(o.action)) { - Dialog.confirm(self, _t("The Microsoft Synchronization needs to be configured before you can use it, do you want to do it now?"), { + Dialog.confirm(self, _t("The Outlook Synchronization needs to be configured before you can use it, do you want to do it now?"), { confirm_callback: function() { self.do_action(o.action); }, title: _t('Configuration'), }); } else { - Dialog.alert(self, _t("An administrator needs to configure Microsoft Synchronization before you can use it!"), { + Dialog.alert(self, _t("An administrator needs to configure Outlook Synchronization before you can use it!"), { title: _t('Configuration'), }); } @@ -104,7 +129,7 @@ const MicrosoftCalendarRenderer = CalendarRenderer.include({ //-------------------------------------------------------------------------- /** - * Adds the Sync with Microsoft button in the sidebar + * Adds the Sync with Outlook button in the sidebar * * @private */ @@ -113,12 +138,16 @@ const MicrosoftCalendarRenderer = CalendarRenderer.include({ this._super.apply(this, arguments); this.$microsoftButton = $(); if (this.model === "calendar.event") { - this.$microsoftButton = $('<button/>', {type: 'button', html: _t("Sync with <b>Microsoft</b>")}) + if (this.state.microsoft_is_sync) { + this.$microsoftButton = $('<span/>', {html: _t("Synched with Outlook")}) + .addClass('o_microsoft_sync badge badge-pill badge-success') + .prepend($('<i/>', {class: "fa mr-2 fa-check"})) + .appendTo(self.$sidebar); + } else { + this.$microsoftButton = $('<button/>', {type: 'button', html: _t("Sync with <b>Outlook</b>")}) .addClass('o_microsoft_sync_button oe_button btn btn-secondary') - .prepend($('<img/>', { - src: "/microsoft_calendar/static/src/img/calendar_outlook_32.png", - })) .appendTo(self.$sidebar); + } } }, diff --git a/addons/microsoft_calendar/static/src/scss/microsoft_calendar.scss b/addons/microsoft_calendar/static/src/scss/microsoft_calendar.scss index b223bcdf965..2f1fa96bb6b 100644 --- a/addons/microsoft_calendar/static/src/scss/microsoft_calendar.scss +++ b/addons/microsoft_calendar/static/src/scss/microsoft_calendar.scss @@ -1,10 +1,12 @@ .o_microsoft_sync_button { - display: block; margin: auto; > img { margin-right: 10px; } } +.o_microsoft_sync.badge { + border: none; +} img.calendar_img_tuto { margin: 0 0 10px 50px; diff --git a/addons/microsoft_calendar/wizard/reset_account_views.xml b/addons/microsoft_calendar/wizard/reset_account_views.xml index 0fb789fe701..1646c6e9db4 100644 --- a/addons/microsoft_calendar/wizard/reset_account_views.xml +++ b/addons/microsoft_calendar/wizard/reset_account_views.xml @@ -5,7 +5,7 @@ <field name="model">microsoft.calendar.account.reset</field> <field name="arch" type="xml"> <form> - <h1>Reset Microsoft Calendar Account</h1> + <h1>Reset Outlook Calendar Account</h1> <group> <field name="delete_policy" widget="radio"/> <field name="sync_policy" widget="radio"/> |
