[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
This commit is contained in:
david 2022-04-18 11:52:29 +02:00 committed by Enric Tobella
parent cdc606b566
commit 607faa0857
5 changed files with 23 additions and 31 deletions

View File

@ -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):

View File

@ -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

View File

@ -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;
});
},
});

View File

@ -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):

View File

@ -52,7 +52,7 @@
</field>
<field name="user_id" position="after">
<field
name="user_id"
name="team_user_id"
attrs="{'invisible': [('team_id', '!=', False)]}"
domain="[('activity_team_ids', '=', team_id)]"
/>