diff --git a/mail_activity_team/models/res_users.py b/mail_activity_team/models/res_users.py index f5a1f892..286d3586 100644 --- a/mail_activity_team/models/res_users.py +++ b/mail_activity_team/models/res_users.py @@ -24,7 +24,7 @@ class ResUsers(models.Model): act.date_deadline::date > 0 Then 'overdue' WHEN %(today)s::date - act.date_deadline::date < 0 Then 'planned' - END AS states + END AS states, act.user_id as user_id FROM mail_activity AS act JOIN ir_model AS m ON act.res_model_id = m.id WHERE team_id in ( @@ -32,9 +32,9 @@ class ResUsers(models.Model): FROM mail_activity_team_users_rel WHERE res_users_id = %(user_id)s ) - GROUP BY m.id, states, act.res_model; + GROUP BY m.id, states, act.res_model, act.user_id; """ - user = user_id if user_id else self.env.uid, + user = user_id if user_id else self.env.uid self.env.cr.execute(query, { 'today': fields.Date.context_today(self), 'user_id': user, @@ -60,4 +60,9 @@ class ResUsers(models.Model): if activity['states'] in ('today', 'overdue'): user_activities[activity['model']]['total_count'] += activity[ 'count'] + if activity['user_id'] == user: + user_activities[ + activity['model'] + ]['total_count'] -= activity['count'] + return list(user_activities.values()) diff --git a/mail_activity_team/static/src/js/systray.js b/mail_activity_team/static/src/js/systray.js index 6fc55b74..3a64a7be 100644 --- a/mail_activity_team/static/src/js/systray.js +++ b/mail_activity_team/static/src/js/systray.js @@ -13,7 +13,16 @@ odoo.define('mail_activity_team.systray', function (require) { this.$filter_buttons = this.$('.o_filter_button'); this.$my_activities = this.$filter_buttons.first(); this.filter = 'my'; + session.user_context = _.extend({}, session.user_context, { + 'team_activities': false + }); }, + + _updateCounter: function (data) { + this._super.apply(this, arguments); + this.$('.o_new_notification_counter').text(this.activityCounter); + }, + on_click_filter_button: function (event) { var self = this; @@ -22,16 +31,11 @@ odoo.define('mail_activity_team.systray', function (require) { var $target = $(event.currentTarget); $target.addClass('active'); self.filter = $target.data('filter'); - if (self.filter === 'team') { - session.user_context = _.extend({}, session.user_context, { - 'team_activities': true - }); - } - else if (self.filter == 'my'){ - session.user_context = _.extend({}, session.user_context, { - 'team_activities': false, - }); - } + + session.user_context = _.extend({}, session.user_context, { + 'team_activities': self.filter === 'team' + }); + self._updateActivityPreview(); }, @@ -65,6 +69,31 @@ odoo.define('mail_activity_team.systray', function (require) { }); } }, + _getActivityData: function(){ + var self = this; + return self._super.apply(self, arguments).then(function (data) { + session.user_context = _.extend({}, session.user_context, { + 'team_activities': !session.user_context['team_activities'], + }); + + self._rpc({ + model: 'res.users', + method: 'activity_user_count', + kwargs: { + context: session.user_context, + }, + }).then(function (data) { + self.activityCounter += _.reduce(data, function( + total_count, p_data + ){ return total_count + p_data.total_count; }, 0); + self.$('.o_new_notification_counter').text(self.activityCounter); + self.$el.toggleClass('o_no_notification', !self.activityCounter); + session.user_context = _.extend({}, session.user_context, { + 'team_activities': !session.user_context['team_activities'], + }); + }); + }); + } }); }); diff --git a/mail_activity_team/static/src/less/systray.less b/mail_activity_team/static/src/less/systray.less new file mode 100644 index 00000000..9690aef1 --- /dev/null +++ b/mail_activity_team/static/src/less/systray.less @@ -0,0 +1,7 @@ +.o_new_notification_counter { + .o-position-absolute(@top: 20%, @right: 1px); + background: @odoo-brand-optional; + color: white; + padding: 0em 0.3em; + font-size: 0.7em; +} diff --git a/mail_activity_team/static/src/xml/systray.xml b/mail_activity_team/static/src/xml/systray.xml index 03ee5757..5d76f1c6 100644 --- a/mail_activity_team/static/src/xml/systray.xml +++ b/mail_activity_team/static/src/xml/systray.xml @@ -10,6 +10,9 @@ + + + diff --git a/mail_activity_team/tests/test_mail_activity_team.py b/mail_activity_team/tests/test_mail_activity_team.py index c5d58396..908a657d 100644 --- a/mail_activity_team/tests/test_mail_activity_team.py +++ b/mail_activity_team/tests/test_mail_activity_team.py @@ -123,4 +123,4 @@ class TestMailActivityTeam(TransactionCase): ).activity_user_count( user_id=self.employee.id ) - self.assertEqual(res[0]['total_count'], 1) + self.assertEqual(res[0]['total_count'], 0) diff --git a/mail_activity_team/views/assets_backend.xml b/mail_activity_team/views/assets_backend.xml index ff1623cd..51f10ca8 100644 --- a/mail_activity_team/views/assets_backend.xml +++ b/mail_activity_team/views/assets_backend.xml @@ -4,6 +4,7 @@ inherit_id="web.assets_backend">