Browse Source

[11.0][IMP] Extended activity widget

pull/389/head
Jaime Arroyo 6 years ago
parent
commit
27c5a810e4
  1. 2
      mail_activity_team/models/mail_activity.py
  2. 3
      mail_activity_team/models/mail_activity_mixin.py
  3. 21
      mail_activity_team/models/res_users.py
  4. 36
      mail_activity_team/static/src/js/systray.js
  5. 2
      mail_activity_team/static/src/xml/systray.xml
  6. 8
      mail_activity_team/tests/test_mail_activity_team.py
  7. 2
      mail_activity_team/views/assets_backend.xml
  8. 3
      mail_activity_team/views/mail_activity_views.xml

2
mail_activity_team/models/mail_activity.py

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

3
mail_activity_team/models/mail_activity_mixin.py

@ -1,7 +1,6 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models, fields, _
from odoo.exceptions import ValidationError
from odoo import api, models, fields
class MailActivityMixin(models.AbstractModel): class MailActivityMixin(models.AbstractModel):

21
mail_activity_team/models/res_users.py

@ -13,27 +13,31 @@ class ResUsers(models.Model):
) )
@api.model @api.model
def activity_user_count(self):
def activity_user_count(self, user_id=False):
if not self._context.get('team_activities', False): if not self._context.get('team_activities', False):
return super().activity_user_count() return super().activity_user_count()
query = """SELECT m.id, count(*), act.res_model as model, query = """SELECT m.id, count(*), act.res_model as model,
CASE 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'
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 END AS states
FROM mail_activity AS act FROM mail_activity AS act
JOIN ir_model AS m ON act.res_model_id = m.id JOIN ir_model AS m ON act.res_model_id = m.id
WHERE team_id in ( WHERE team_id in (
select mail_activity_team_id from mail_activity_team_users_rel
where res_users_id =
%(user_id)s
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; GROUP BY m.id, states, act.res_model;
""" """
user = user_id if user_id else self.env.uid,
self.env.cr.execute(query, { self.env.cr.execute(query, {
'today': fields.Date.context_today(self), 'today': fields.Date.context_today(self),
'user_id': self.env.uid,
'user_id': user,
}) })
activity_data = self.env.cr.dictfetchall() activity_data = self.env.cr.dictfetchall()
model_ids = [a['id'] for a in activity_data] model_ids = [a['id'] for a in activity_data]
@ -56,5 +60,4 @@ class ResUsers(models.Model):
if activity['states'] in ('today', 'overdue'): if activity['states'] in ('today', 'overdue'):
user_activities[activity['model']]['total_count'] += activity[ user_activities[activity['model']]['total_count'] += activity[
'count'] 'count']
return list(user_activities.values()) return list(user_activities.values())

36
mail_activity_team/static/src/js/systray.js

@ -1,5 +1,5 @@
odoo.define('mail_activity_team.systray', function (require) { odoo.define('mail_activity_team.systray', function (require) {
"use strict";
"use strict";
var systray = require('mail.systray'); var systray = require('mail.systray');
var session = require("web.session"); var session = require("web.session");
@ -8,9 +8,10 @@ odoo.define('mail_activity_team.systray', function (require) {
events: _.extend({}, systray.ActivityMenu.prototype.events, { events: _.extend({}, systray.ActivityMenu.prototype.events, {
'click .o_filter_button': 'on_click_filter_button', 'click .o_filter_button': 'on_click_filter_button',
}), }),
start: function() {
start: function () {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.$filter_buttons = this.$('.o_filter_button'); this.$filter_buttons = this.$('.o_filter_button');
this.$my_activities = this.$filter_buttons.first();
this.filter = 'my'; this.filter = 'my';
}, },
on_click_filter_button: function (event) { on_click_filter_button: function (event) {
@ -21,29 +22,33 @@ odoo.define('mail_activity_team.systray', function (require) {
var $target = $(event.currentTarget); var $target = $(event.currentTarget);
$target.addClass('active'); $target.addClass('active');
self.filter = $target.data('filter'); self.filter = $target.data('filter');
if (self.filter == 'team'){
if (self.filter === 'team') {
session.user_context = _.extend({}, session.user_context, { session.user_context = _.extend({}, session.user_context, {
'team_activities': true 'team_activities': true
}); });
} }
else if (self.filter == 'my'){ else if (self.filter == 'my'){
session.user_context = _.extend({}, session.user_context, { session.user_context = _.extend({}, session.user_context, {
'team_activities': false
'team_activities': false,
}); });
} }
self._updateActivityPreview(); self._updateActivityPreview();
}, },
_onActivityFilterClick: function (event){
if (this.filter == 'my'){
_onActivityFilterClick: function (event) {
if (this.filter === 'my') {
this._super.apply(this, arguments); this._super.apply(this, arguments);
} }
if (this.filter == 'team'){
var data = _.extend({}, $(event.currentTarget).data(), $(event.target).data());
if (this.filter === 'team') {
var data = _.extend(
{},
$(event.currentTarget).data(),
$(event.target).data()
);
var context = {}; var context = {};
if (data.filter === 'my') { if (data.filter === 'my') {
context['search_default_activities_overdue'] = 1;
context['search_default_activities_today'] = 1;
context.search_default_activities_overdue = 1;
context.search_default_activities_today = 1;
} else { } else {
context['search_default_activities_' + data.filter] = 1; context['search_default_activities_' + data.filter] = 1;
} }
@ -53,18 +58,13 @@ odoo.define('mail_activity_team.systray', function (require) {
res_model: data.res_model, res_model: data.res_model,
views: [[false, 'kanban'], [false, 'form']], views: [[false, 'kanban'], [false, 'form']],
search_view_id: [false], search_view_id: [false],
domain: ['|', ['activity_user_id', '=', session.uid], ['activity_team_user_ids', 'in', session.uid]],
domain: [
['activity_team_user_ids', 'in', session.uid]
],
context:context, context:context,
}); });
} }
}, },
/*
_getActivityData: function(){
var self = this;
this._super.apply(this, arguments).then(function () {
});
},*/
}); });
}); });

2
mail_activity_team/static/src/xml/systray.xml

@ -12,4 +12,4 @@
</t> </t>
</t> </t>
</templates>
</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.member_ids = [(3, self.employee.id)]
self.team2._onchange_member_ids() self.team2._onchange_member_ids()
self.assertFalse(self.team2.user_id) 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'], 1)

2
mail_activity_team/views/assets_backend.xml

@ -6,4 +6,4 @@
<script type="text/javascript" src="/mail_activity_team/static/src/js/systray.js"/> <script type="text/javascript" src="/mail_activity_team/static/src/js/systray.js"/>
</xpath> </xpath>
</template> </template>
</odoo>
</odoo>

3
mail_activity_team/views/mail_activity_views.xml

@ -5,7 +5,7 @@
<field name="name">mail.activity.view.form.popup</field> <field name="name">mail.activity.view.form.popup</field>
<field name="model">mail.activity</field> <field name="model">mail.activity</field>
<field name="inherit_id" ref="mail.mail_activity_view_form_popup"/> <field name="inherit_id" ref="mail.mail_activity_view_form_popup"/>
<field name="arch" type="xml">s
<field name="arch" type="xml">
<field name="user_id" position="after"> <field name="user_id" position="after">
<field name="team_id" options="{'no_create': True, 'no_open': True}"/> <field name="team_id" options="{'no_create': True, 'no_open': True}"/>
</field> </field>
@ -68,6 +68,5 @@
<filter name='team' string="Team" context="{'group_by': 'team_id'}"/> <filter name='team' string="Team" context="{'group_by': 'team_id'}"/>
</group> </group>
</field> </field>
</record> </record>
</odoo> </odoo>
Loading…
Cancel
Save