[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. # Copyright 2018-22 ForgeFlow 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).
import json
from odoo import SUPERUSER_ID, _, api, fields, models from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
@ -27,15 +26,6 @@ class MailActivity(models.Model):
team_id = fields.Many2one( team_id = fields.Many2one(
comodel_name="mail.activity.team", default=lambda s: s._get_default_team_id() 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") @api.onchange("user_id")
def _onchange_user_id(self): def _onchange_user_id(self):

View File

@ -14,7 +14,7 @@ class ResUsers(models.Model):
@api.model @api.model
def systray_get_activities(self): 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() return super().systray_get_activities()
query = """SELECT m.id, count(*), act.res_model as model, query = """SELECT m.id, count(*), act.res_model as model,
CASE CASE

View File

@ -11,10 +11,11 @@ ActivityMenu.include({
this.$filter_buttons = this.$(".o_filter_button"); this.$filter_buttons = this.$(".o_filter_button");
this.$my_activities = this.$filter_buttons.first(); this.$my_activities = this.$filter_buttons.first();
this.filter = "my"; this.filter = "my";
this.user_context = session.user_context; this._update_team_activities_context();
this.user_context = _.extend({}, session.user_context, { },
team_activities: false,
}); _update_team_activities_context: function () {
session.user_context.team_activities = this.filter === "team";
}, },
_updateCounter: function () { _updateCounter: function () {
@ -23,18 +24,13 @@ ActivityMenu.include({
}, },
_onClickFilterButton: function (event) { _onClickFilterButton: function (event) {
var self = this;
event.stopPropagation(); event.stopPropagation();
self.$filter_buttons.removeClass("active"); this.$filter_buttons.removeClass("active");
var $target = $(event.currentTarget); var $target = $(event.currentTarget);
$target.addClass("active"); $target.addClass("active");
self.filter = $target.data("filter"); this.filter = $target.data("filter");
this._update_team_activities_context();
self.user_context = _.extend({}, session.user_context, { this._updateActivityPreview();
team_activities: self.filter === "team",
});
self._updateActivityPreview();
}, },
_onActivityFilterClick: function (event) { _onActivityFilterClick: function (event) {
if (this.filter === "my") { if (this.filter === "my") {
@ -63,12 +59,21 @@ ActivityMenu.include({
[false, "form"], [false, "form"],
], ],
search_view_id: [false], search_view_id: [false],
domain: [["activity_team_user_ids", "in", session.uid]], domain: [["activity_team_user_ids", "in", [session.uid]]],
context: context, 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 () { _getActivityData: function () {
if (this.filter !== "team") {
return this._super.apply(this, arguments);
}
var self = this; var self = this;
return self return self
@ -89,6 +94,8 @@ ActivityMenu.include({
); );
self.$(".o_notification_counter").text(self.activityCounter); self.$(".o_notification_counter").text(self.activityCounter);
self.$el.toggleClass("o_no_notification", !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. # Copyright 2018-22 ForgeFlow 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).
import json
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tests.common import Form, TransactionCase from odoo.tests.common import Form, TransactionCase
@ -202,10 +201,6 @@ class TestMailActivityTeam(TransactionCase):
self.team2.member_ids = self.employee2 self.team2.member_ids = self.employee2
with Form(self.act2) as form: with Form(self.act2) as form:
form.team_id = self.team2 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) self.assertEqual(form.user_id, self.employee2)
def test_activity_onchanges_team_different_member_no_leader(self): def test_activity_onchanges_team_different_member_no_leader(self):

View File

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