summaryrefslogtreecommitdiff
path: root/addons/microsoft_calendar
diff options
context:
space:
mode:
authorjbm-odoo <jbm@odoo.com>2020-09-04 09:16:35 +0000
committerjbm-odoo <jbm@odoo.com>2020-09-16 12:48:50 +0000
commit255eb91dd5e9fb39a7625064d1ba8e0b492bfb85 (patch)
tree7dd2d8a50e037a04763e62f6f20d6526b44a7a7a /addons/microsoft_calendar
parenta677859a03c86bf6ac791c31f52ce8609bcba594 (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>
Diffstat (limited to 'addons/microsoft_calendar')
-rw-r--r--addons/microsoft_calendar/__manifest__.py1
-rw-r--r--addons/microsoft_calendar/data/microsoft_calendar_data.xml18
-rw-r--r--addons/microsoft_calendar/models/microsoft_sync.py2
-rw-r--r--addons/microsoft_calendar/models/res_users.py2
-rw-r--r--addons/microsoft_calendar/static/src/js/microsoft_calendar.js49
-rw-r--r--addons/microsoft_calendar/static/src/scss/microsoft_calendar.scss4
-rw-r--r--addons/microsoft_calendar/wizard/reset_account_views.xml2
7 files changed, 64 insertions, 14 deletions
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"/>