Browse Source

Merge 840bb807a4 into 65fa5e50a2

pull/389/merge
Jaime Arroyo 5 years ago
committed by GitHub
parent
commit
b36f10f578
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      mail_activity_team/__manifest__.py
  2. 1
      mail_activity_team/models/__init__.py
  3. 2
      mail_activity_team/models/mail_activity.py
  4. 23
      mail_activity_team/models/mail_activity_mixin.py
  5. 57
      mail_activity_team/models/res_users.py
  6. 99
      mail_activity_team/static/src/js/systray.js
  7. 7
      mail_activity_team/static/src/less/systray.less
  8. 18
      mail_activity_team/static/src/xml/systray.xml
  9. 8
      mail_activity_team/tests/test_mail_activity_team.py
  10. 10
      mail_activity_team/views/assets_backend.xml
  11. 1
      mail_activity_team/views/mail_activity_views.xml

5
mail_activity_team/__manifest__.py

@ -14,10 +14,15 @@
'mail_activity_board',
],
'data': [
'views/assets_backend.xml',
'security/ir.model.access.csv',
'security/mail_activity_team_security.xml',
'views/mail_activity_team_views.xml',
'views/mail_activity_views.xml',
'views/res_users_views.xml',
],
'qweb': [
'static/src/xml/systray.xml',
],
}

1
mail_activity_team/models/__init__.py

@ -1,3 +1,4 @@
from . import mail_activity_team
from . import mail_activity
from . import res_users
from . import mail_activity_mixin

2
mail_activity_team/models/mail_activity.py

@ -19,6 +19,8 @@ class MailActivity(models.Model):
('res_model_ids', 'in', model.ids)])
return self.env['mail.activity.team'].search(domain, limit=1)
user_id = fields.Many2one(required=False)
team_id = fields.Many2one(
comodel_name='mail.activity.team',
default=lambda s: s._get_default_team_id(),

23
mail_activity_team/models/mail_activity_mixin.py

@ -0,0 +1,23 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models, fields
class MailActivityMixin(models.AbstractModel):
_inherit = 'mail.activity.mixin'
activity_team_user_ids = fields.Many2many(
comodel_name='res.users', string='test field',
compute="_compute_activity_team_user_ids",
search="_search_activity_team_user_ids",
)
@api.depends("activity_ids")
def _compute_activity_team_user_ids(self):
for rec in self:
rec.activity_team_user_ids = rec.activity_ids.mapped(
"team_id.member_ids")
@api.model
def _search_activity_team_user_ids(self, operator, operand):
return [('activity_ids.team_id.member_ids', operator, operand)]

57
mail_activity_team/models/res_users.py

@ -1,6 +1,6 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo import api, models, fields, modules
class ResUsers(models.Model):
@ -11,3 +11,58 @@ class ResUsers(models.Model):
relation='mail_activity_team_users_rel',
string="Activity Teams",
)
@api.model
def activity_user_count(self, user_id=False):
if not self._context.get('team_activities', False):
return super().activity_user_count()
query = """SELECT m.id, count(*), act.res_model as model,
CASE
WHEN %(today)s::date -
act.date_deadline::date = 0 Then 'today'
WHEN %(today)s::date -
act.date_deadline::date > 0 Then 'overdue'
WHEN %(today)s::date -
act.date_deadline::date < 0 Then 'planned'
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 (
SELECT mail_activity_team_id
FROM mail_activity_team_users_rel
WHERE res_users_id = %(user_id)s
)
GROUP BY m.id, states, act.res_model, act.user_id;
"""
user = user_id if user_id else self.env.uid
self.env.cr.execute(query, {
'today': fields.Date.context_today(self),
'user_id': user,
})
activity_data = self.env.cr.dictfetchall()
model_ids = [a['id'] for a in activity_data]
model_names = {n[0]: n[1] for n in
self.env['ir.model'].browse(model_ids).name_get()}
user_activities = {}
for activity in activity_data:
if not user_activities.get(activity['model']):
user_activities[activity['model']] = {
'name': model_names[activity['id']],
'model': activity['model'],
'icon': modules.module.get_module_icon(
self.env[activity['model']]._original_module),
'total_count': 0, 'today_count': 0, 'overdue_count': 0,
'planned_count': 0,
}
user_activities[activity['model']][
'%s_count' % activity['states']] += activity['count']
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())

99
mail_activity_team/static/src/js/systray.js

@ -0,0 +1,99 @@
odoo.define('mail_activity_team.systray', function (require) {
"use strict";
var systray = require('mail.systray');
var session = require("web.session");
systray.ActivityMenu.include({
events: _.extend({}, systray.ActivityMenu.prototype.events, {
'click .o_filter_button': 'on_click_filter_button',
}),
start: function () {
this._super.apply(this, arguments);
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;
event.stopPropagation();
self.$filter_buttons.removeClass('active');
var $target = $(event.currentTarget);
$target.addClass('active');
self.filter = $target.data('filter');
session.user_context = _.extend({}, session.user_context, {
'team_activities': self.filter === 'team'
});
self._updateActivityPreview();
},
_onActivityFilterClick: function (event) {
if (this.filter === 'my') {
this._super.apply(this, arguments);
}
if (this.filter === 'team') {
var data = _.extend(
{},
$(event.currentTarget).data(),
$(event.target).data()
);
var context = {};
if (data.filter === 'my') {
context.search_default_activities_overdue = 1;
context.search_default_activities_today = 1;
} else {
context['search_default_activities_' + data.filter] = 1;
}
this.do_action({
type: 'ir.actions.act_window',
name: data.model_name,
res_model: data.res_model,
views: [[false, 'kanban'], [false, 'form']],
search_view_id: [false],
domain: [
['activity_team_user_ids', 'in', session.uid]
],
context:context,
});
}
},
_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;
}

18
mail_activity_team/static/src/xml/systray.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-extend="mail.chat.ActivityMenu">
<t t-jquery=".o_mail_navbar_dropdown_channels" t-operation="before">
<li class="o_mail_navbar_dropdown_top">
<div>
<button type="button" class="btn btn-sm o_filter_button active" data-filter='my'> My Activities </button>
<button type="button" class="btn btn-sm o_filter_button" data-filter='team'> Team Activities </button>
</div>
</li>
</t>
<t t-jquery=".o_notification_counter" t-operation="replace">
<span class="o_new_notification_counter badge"/>
</t>
</t>
</templates>

8
mail_activity_team/tests/test_mail_activity_team.py

@ -116,3 +116,11 @@ class TestMailActivityTeam(TransactionCase):
self.team2.member_ids = [(3, self.employee.id)]
self.team2._onchange_member_ids()
self.assertFalse(self.team2.user_id)
def test_activity_count(self):
res = self.env['res.users'].with_context(
{'team_activities': True}
).activity_user_count(
user_id=self.employee.id
)
self.assertEqual(res[0]['total_count'], 0)

10
mail_activity_team/views/assets_backend.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="mail assets"
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>

1
mail_activity_team/views/mail_activity_views.xml

@ -68,6 +68,5 @@
<filter name='team' string="Team" context="{'group_by': 'team_id'}"/>
</group>
</field>
</record>
</odoo>
Loading…
Cancel
Save