Browse Source

FIX notification counter

pull/389/head
Jaime Arroyo 6 years ago
parent
commit
840bb807a4
  1. 11
      mail_activity_team/models/res_users.py
  2. 49
      mail_activity_team/static/src/js/systray.js
  3. 7
      mail_activity_team/static/src/less/systray.less
  4. 3
      mail_activity_team/static/src/xml/systray.xml
  5. 2
      mail_activity_team/tests/test_mail_activity_team.py
  6. 1
      mail_activity_team/views/assets_backend.xml

11
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())

49
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'],
});
});
});
}
});
});

7
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;
}

3
mail_activity_team/static/src/xml/systray.xml

@ -10,6 +10,9 @@
</div>
</li>
</t>
<t t-jquery=".o_notification_counter" t-operation="replace">
<span class="o_new_notification_counter badge"/>
</t>
</t>
</templates>

2
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)

1
mail_activity_team/views/assets_backend.xml

@ -4,6 +4,7 @@
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/mail_activity_team/static/src/js/systray.js"/>
<link rel="stylesheet" href="/mail_activity_team/static/src/less/systray.less" type="text/less"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save