From 27c5a810e4f6b651865bf1c6cfe2b28e787cd959 Mon Sep 17 00:00:00 2001 From: Jaime Arroyo Date: Fri, 31 May 2019 08:58:14 +0200 Subject: [PATCH] [11.0][IMP] Extended activity widget --- mail_activity_team/models/mail_activity.py | 2 ++ .../models/mail_activity_mixin.py | 3 +- mail_activity_team/models/res_users.py | 21 ++++++----- mail_activity_team/static/src/js/systray.js | 36 +++++++++---------- mail_activity_team/static/src/xml/systray.xml | 2 +- .../tests/test_mail_activity_team.py | 8 +++++ mail_activity_team/views/assets_backend.xml | 2 +- .../views/mail_activity_views.xml | 3 +- 8 files changed, 44 insertions(+), 33 deletions(-) diff --git a/mail_activity_team/models/mail_activity.py b/mail_activity_team/models/mail_activity.py index 1fccf746..90490e57 100644 --- a/mail_activity_team/models/mail_activity.py +++ b/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(), diff --git a/mail_activity_team/models/mail_activity_mixin.py b/mail_activity_team/models/mail_activity_mixin.py index 79382098..0c5035bb 100644 --- a/mail_activity_team/models/mail_activity_mixin.py +++ b/mail_activity_team/models/mail_activity_mixin.py @@ -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): diff --git a/mail_activity_team/models/res_users.py b/mail_activity_team/models/res_users.py index bc799e71..f5a1f892 100644 --- a/mail_activity_team/models/res_users.py +++ b/mail_activity_team/models/res_users.py @@ -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()) diff --git a/mail_activity_team/static/src/js/systray.js b/mail_activity_team/static/src/js/systray.js index 520cf08c..6fc55b74 100644 --- a/mail_activity_team/static/src/js/systray.js +++ b/mail_activity_team/static/src/js/systray.js @@ -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 () { - - }); - },*/ }); }); diff --git a/mail_activity_team/static/src/xml/systray.xml b/mail_activity_team/static/src/xml/systray.xml index 747b9999..03ee5757 100644 --- a/mail_activity_team/static/src/xml/systray.xml +++ b/mail_activity_team/static/src/xml/systray.xml @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/mail_activity_team/tests/test_mail_activity_team.py b/mail_activity_team/tests/test_mail_activity_team.py index 413e4122..c5d58396 100644 --- a/mail_activity_team/tests/test_mail_activity_team.py +++ b/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'], 1) diff --git a/mail_activity_team/views/assets_backend.xml b/mail_activity_team/views/assets_backend.xml index 470fc8a8..ff1623cd 100644 --- a/mail_activity_team/views/assets_backend.xml +++ b/mail_activity_team/views/assets_backend.xml @@ -6,4 +6,4 @@