Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mail_activity_team: Fix bug of the Team Activities filter. #1280

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mail_activity_team/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def _get_default_team_id(self, user_id=None):
)

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(),
index=True,
)

@api.onchange("user_id")
Expand Down
36 changes: 19 additions & 17 deletions mail_activity_team/models/mail_activity_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,13 @@ def _compute_activity_team_user_ids(self):
def _search_my_activity_date_deadline(self, operator, operand):
if not self._context.get("team_activities", False):
return super()._search_my_activity_date_deadline(operator, operand)
query = """
SELECT res_users_id
FROM mail_activity_team_users_rel
WHERE mail_activity_team_id IN (
SELECT mail_activity_team_id
FROM mail_activity_team_users_rel
WHERE res_users_id = %(user_id)s)
"""
user = self.env.uid
self.env.cr.execute(
query,
{
"user_id": user,
},
)
users = [row[0] for row in self.env.cr.fetchall()]
activity_ids = self.env["mail.activity"]._search(
[
("date_deadline", operator, operand),
("res_model", "=", self._name),
("user_id", "in", users),
"|",
("user_id", "=", self.env.user.id),
("team_id", "in", self.env.user.activity_team_ids.ids),
ntodorova marked this conversation as resolved.
Show resolved Hide resolved
]
)
return [("activity_ids", "in", activity_ids)]
Expand Down Expand Up @@ -96,3 +82,19 @@ def activity_schedule(
note=note,
**act_values
)

@api.depends(
"activity_ids.date_deadline", "activity_ids.user_id", "activity_ids.team_id"
)
@api.depends_context("uid")
def _compute_my_activity_date_deadline(self):
for record in self:
record.my_activity_date_deadline = next(
(
activity.date_deadline
for activity in record.activity_ids
if activity.user_id.id == record.env.uid
or activity.team_id in record.env.user.activity_team_ids
),
False,
)
23 changes: 23 additions & 0 deletions mail_activity_team/tests/test_mail_activity_team.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2018-22 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import date

from odoo.exceptions import ValidationError
from odoo.tests.common import Form, TransactionCase

Expand Down Expand Up @@ -318,3 +320,24 @@ def test_schedule_activity_from_server_action(self):
action.activity_team_id = self.team2
action.with_context(active_model=partner._name, active_ids=partner.ids).run()
self.assertEqual(partner.activity_ids[-1].team_id, self.team2)

def test_my_activity_date_deadline(self):
ntodorova marked this conversation as resolved.
Show resolved Hide resolved
"""This test case checks
- if the team activities are properly filtered
"""
today = date.today()
self.act2.write(
{
"user_id": False,
"team_id": self.team1.id,
"date_deadline": today,
}
)
partner = (
self.env["res.partner"]
.with_context(team_activities=True)
.with_user(self.employee.id)
.search([("my_activity_date_deadline", "=", today)])
)
self.assertEqual(partner, self.partner_client)
self.assertEqual(partner.my_activity_date_deadline, today)
Loading