mirror of https://github.com/OCA/social.git
[11.0][IMP] Extended activity widget
parent
c3b3dffe97
commit
99d31d15e6
|
@ -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(),
|
||||
|
|
|
@ -1,7 +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 api, models, fields, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo import api, models, fields
|
||||
|
||||
|
||||
class MailActivityMixin(models.AbstractModel):
|
||||
|
|
|
@ -13,27 +13,31 @@ class ResUsers(models.Model):
|
|||
)
|
||||
|
||||
@api.model
|
||||
def activity_user_count(self):
|
||||
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'
|
||||
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
|
||||
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
|
||||
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;
|
||||
"""
|
||||
user = user_id if user_id else self.env.uid,
|
||||
self.env.cr.execute(query, {
|
||||
'today': fields.Date.context_today(self),
|
||||
'user_id': self.env.uid,
|
||||
'user_id': user,
|
||||
})
|
||||
activity_data = self.env.cr.dictfetchall()
|
||||
model_ids = [a['id'] for a in activity_data]
|
||||
|
@ -56,5 +60,4 @@ class ResUsers(models.Model):
|
|||
if activity['states'] in ('today', 'overdue'):
|
||||
user_activities[activity['model']]['total_count'] += activity[
|
||||
'count']
|
||||
|
||||
return list(user_activities.values())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
odoo.define('mail_activity_team.systray', function (require) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
var systray = require('mail.systray');
|
||||
var session = require("web.session");
|
||||
|
@ -8,9 +8,10 @@ odoo.define('mail_activity_team.systray', function (require) {
|
|||
events: _.extend({}, systray.ActivityMenu.prototype.events, {
|
||||
'click .o_filter_button': 'on_click_filter_button',
|
||||
}),
|
||||
start: function() {
|
||||
start: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.$filter_buttons = this.$('.o_filter_button');
|
||||
this.$my_activities = this.$filter_buttons.first();
|
||||
this.filter = 'my';
|
||||
},
|
||||
on_click_filter_button: function (event) {
|
||||
|
@ -21,29 +22,33 @@ odoo.define('mail_activity_team.systray', function (require) {
|
|||
var $target = $(event.currentTarget);
|
||||
$target.addClass('active');
|
||||
self.filter = $target.data('filter');
|
||||
if (self.filter == 'team'){
|
||||
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
|
||||
'team_activities': false,
|
||||
});
|
||||
}
|
||||
self._updateActivityPreview();
|
||||
|
||||
},
|
||||
_onActivityFilterClick: function (event){
|
||||
if (this.filter == 'my'){
|
||||
_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());
|
||||
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;
|
||||
context.search_default_activities_overdue = 1;
|
||||
context.search_default_activities_today = 1;
|
||||
} else {
|
||||
context['search_default_activities_' + data.filter] = 1;
|
||||
}
|
||||
|
@ -53,18 +58,13 @@ odoo.define('mail_activity_team.systray', function (require) {
|
|||
res_model: data.res_model,
|
||||
views: [[false, 'kanban'], [false, 'form']],
|
||||
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,
|
||||
});
|
||||
}
|
||||
},
|
||||
/*
|
||||
_getActivityData: function(){
|
||||
var self = this;
|
||||
this._super.apply(this, arguments).then(function () {
|
||||
|
||||
});
|
||||
},*/
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -12,4 +12,4 @@
|
|||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
</templates>
|
||||
|
|
|
@ -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'], 1)
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
<script type="text/javascript" src="/mail_activity_team/static/src/js/systray.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<field name="name">mail.activity.view.form.popup</field>
|
||||
<field name="model">mail.activity</field>
|
||||
<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="team_id" options="{'no_create': True, 'no_open': True}"/>
|
||||
</field>
|
||||
|
@ -68,6 +68,5 @@
|
|||
<filter name='team' string="Team" context="{'group_by': 'team_id'}"/>
|
||||
</group>
|
||||
</field>
|
||||
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue