From 607faa085764c3e1fa30307cd07ecdef04522f9e Mon Sep 17 00:00:00 2001 From: david Date: Mon, 18 Apr 2022 11:52:29 +0200 Subject: [PATCH] [FIX] mail_activity_team: activity count The user couldn't see the proper count of his own activities. It was allways showing the team activities counter. TT35885 --- mail_activity_team/models/mail_activity.py | 10 ------ mail_activity_team/models/res_users.py | 2 +- .../static/src/js/systray.esm.js | 35 +++++++++++-------- .../tests/test_mail_activity_team.py | 5 --- .../views/mail_activity_views.xml | 2 +- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/mail_activity_team/models/mail_activity.py b/mail_activity_team/models/mail_activity.py index df9add5..7eb0a20 100644 --- a/mail_activity_team/models/mail_activity.py +++ b/mail_activity_team/models/mail_activity.py @@ -1,6 +1,5 @@ # Copyright 2018-22 ForgeFlow S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import json from odoo import SUPERUSER_ID, _, api, fields, models from odoo.exceptions import ValidationError @@ -27,15 +26,6 @@ class MailActivity(models.Model): team_id = fields.Many2one( comodel_name="mail.activity.team", default=lambda s: s._get_default_team_id() ) - user_id_domain = fields.Char(compute="_compute_user_id_domain") - - @api.depends("team_id") - def _compute_user_id_domain(self): - for record in self: - domain = [] - if record.team_id: - domain.append(("id", "in", record.team_id.member_ids.ids)) - record.user_id_domain = json.dumps(domain) @api.onchange("user_id") def _onchange_user_id(self): diff --git a/mail_activity_team/models/res_users.py b/mail_activity_team/models/res_users.py index 1ab0437..c43e006 100644 --- a/mail_activity_team/models/res_users.py +++ b/mail_activity_team/models/res_users.py @@ -14,7 +14,7 @@ class ResUsers(models.Model): @api.model def systray_get_activities(self): - if not self._context.get("team_activities", False): + if not self.env.context.get("team_activities"): return super().systray_get_activities() query = """SELECT m.id, count(*), act.res_model as model, CASE diff --git a/mail_activity_team/static/src/js/systray.esm.js b/mail_activity_team/static/src/js/systray.esm.js index ea10bf8..5d9f39c 100644 --- a/mail_activity_team/static/src/js/systray.esm.js +++ b/mail_activity_team/static/src/js/systray.esm.js @@ -11,10 +11,11 @@ ActivityMenu.include({ this.$filter_buttons = this.$(".o_filter_button"); this.$my_activities = this.$filter_buttons.first(); this.filter = "my"; - this.user_context = session.user_context; - this.user_context = _.extend({}, session.user_context, { - team_activities: false, - }); + this._update_team_activities_context(); + }, + + _update_team_activities_context: function () { + session.user_context.team_activities = this.filter === "team"; }, _updateCounter: function () { @@ -23,18 +24,13 @@ ActivityMenu.include({ }, _onClickFilterButton: function (event) { - var self = this; event.stopPropagation(); - self.$filter_buttons.removeClass("active"); + this.$filter_buttons.removeClass("active"); var $target = $(event.currentTarget); $target.addClass("active"); - self.filter = $target.data("filter"); - - self.user_context = _.extend({}, session.user_context, { - team_activities: self.filter === "team", - }); - - self._updateActivityPreview(); + this.filter = $target.data("filter"); + this._update_team_activities_context(); + this._updateActivityPreview(); }, _onActivityFilterClick: function (event) { if (this.filter === "my") { @@ -63,12 +59,21 @@ ActivityMenu.include({ [false, "form"], ], search_view_id: [false], - domain: [["activity_team_user_ids", "in", session.uid]], + domain: [["activity_team_user_ids", "in", [session.uid]]], context: context, }); } }, + _open_boards_activities_domain: function () { + if (this.filter === "team") { + return {additional_context: {search_default_my_team_activities: 1}}; + } + return this._super.apply(this, arguments); + }, _getActivityData: function () { + if (this.filter !== "team") { + return this._super.apply(this, arguments); + } var self = this; return self @@ -89,6 +94,8 @@ ActivityMenu.include({ ); self.$(".o_notification_counter").text(self.activityCounter); self.$el.toggleClass("o_no_notification", !self.activityCounter); + // Unset context after we gather the info to avoid side effects + session.user_context.team_activities = false; }); }, }); diff --git a/mail_activity_team/tests/test_mail_activity_team.py b/mail_activity_team/tests/test_mail_activity_team.py index 161b0a4..8ea26a8 100644 --- a/mail_activity_team/tests/test_mail_activity_team.py +++ b/mail_activity_team/tests/test_mail_activity_team.py @@ -1,6 +1,5 @@ # Copyright 2018-22 ForgeFlow S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import json from odoo.exceptions import ValidationError from odoo.tests.common import Form, TransactionCase @@ -202,10 +201,6 @@ class TestMailActivityTeam(TransactionCase): self.team2.member_ids = self.employee2 with Form(self.act2) as form: form.team_id = self.team2 - self.assertIn( - form.user_id, - self.env["res.users"].search(json.loads(form.user_id_domain)), - ) self.assertEqual(form.user_id, self.employee2) def test_activity_onchanges_team_different_member_no_leader(self): diff --git a/mail_activity_team/views/mail_activity_views.xml b/mail_activity_team/views/mail_activity_views.xml index 9b341bd..893ef85 100644 --- a/mail_activity_team/views/mail_activity_views.xml +++ b/mail_activity_team/views/mail_activity_views.xml @@ -52,7 +52,7 @@