From c79311d00e17bbfd00a2873afec153d0b57d5d36 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 6 Nov 2019 10:08:42 +0000 Subject: [PATCH] [FIX] calendar: multiple notifications for an event Before this commit, when an event have multiples notifications, if the first notification is not ack when the second notification is shown, not only two are visualized but multiples notifications are raised. Now, only the correct number of notifications are shown. opw-2070852 closes odoo/odoo#39909 X-original-commit: 8ab0bfeaa7b6c3e1642064d123197b1cba74355d Signed-off-by: Aaron Bohy (aab) Co-authored-by: Aaron Bohy Co-authored-by: Lucas Perais --- addons/calendar/models/calendar.py | 1 + .../calendar/static/src/js/base_calendar.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py index 54ea446aed4..597bf760b95 100644 --- a/addons/calendar/models/calendar.py +++ b/addons/calendar/models/calendar.py @@ -454,6 +454,7 @@ class AlarmManager(models.AbstractModel): delta = delta.seconds + delta.days * 3600 * 24 return { + 'alarm_id': alarm.id, 'event_id': meeting.id, 'title': meeting.name, 'message': message, diff --git a/addons/calendar/static/src/js/base_calendar.js b/addons/calendar/static/src/js/base_calendar.js index 0a9dd625662..600ebd4b01a 100644 --- a/addons/calendar/static/src/js/base_calendar.js +++ b/addons/calendar/static/src/js/base_calendar.js @@ -38,12 +38,12 @@ var CalendarNotification = Notification.extend({ }, 'click .link2recall': function() { - this.destroy(true); + this.close(); }, 'click .link2showed': function() { this._rpc({route: '/calendar/notify_ack'}) - .then(this.destroy.bind(this), this.destroy.bind(this)); + .then(this.close.bind(this, false), this.close.bind(this, false)); }, }); }, @@ -57,22 +57,25 @@ WebClient.include({ // Clear previously set timeouts and destroy currently displayed calendar notifications clearTimeout(this.get_next_calendar_notif_timeout); _.each(this.calendar_notif_timeouts, clearTimeout); - _.each(this.calendar_notif, function (notificationID) { - self.call('notification', 'close', notificationID, true); - }); this.calendar_notif_timeouts = {}; - this.calendar_notif = {}; // For each notification, set a timeout to display it _.each(notifications, function(notif) { - self.calendar_notif_timeouts[notif.event_id] = setTimeout(function() { + var key = notif.event_id + ',' + notif.alarm_id; + if (key in self.calendar_notif) { + return; + } + self.calendar_notif_timeouts[key] = setTimeout(function () { var notificationID = self.call('notification', 'notify', { Notification: CalendarNotification, title: notif.title, message: notif.message, eventID: notif.event_id, + onClose: function () { + delete self.calendar_notif[key]; + }, }); - self.calendar_notif[notif.event_id] = notificationID; + self.calendar_notif[key] = notificationID; }, notif.timer * 1000); last_notif_timer = Math.max(last_notif_timer, notif.timer); });