[IMP] mail_activity_team

This commit is contained in:
Olga Marco 2022-06-14 13:58:34 +02:00 committed by Enric Tobella
parent 589f0f7f38
commit bd214206b6
3 changed files with 16 additions and 11 deletions

View File

@ -38,7 +38,7 @@ class MailActivity(models.Model):
if self.team_id and self.user_id in self.team_id.member_ids:
return res
self.team_id = self.with_context(
default_res_model=self.res_model_id.model
default_res_model=self.sudo().res_model_id.model
)._get_default_team_id(user_id=self.user_id.id)
return res
@ -86,9 +86,10 @@ class MailActivity(models.Model):
@api.onchange("activity_type_id")
def _onchange_activity_type_id(self):
super(MailActivity, self)._onchange_activity_type_id()
res = super(MailActivity, self)._onchange_activity_type_id()
if self.activity_type_id.default_team_id:
self.team_id = self.activity_type_id.default_team_id
members = self.activity_type_id.default_team_id.member_ids
if self.user_id not in members and members:
self.user_id = members[:1]
return res

View File

@ -69,7 +69,9 @@ class MailActivityMixin(models.AbstractModel):
if user_id:
team = (
self.env["mail.activity"]
.with_context(default_res_model=self._name,)
.with_context(
default_res_model=self._name,
)
._get_default_team_id(user_id=user_id)
)
act_values.update({"team_id": team.id})

View File

@ -1,10 +1,10 @@
# Copyright 2018-22 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.exceptions import ValidationError
from odoo.tests.common import Form, SavepointCase
from odoo.tests.common import Form, TransactionCase
class TestMailActivityTeam(SavepointCase):
class TestMailActivityTeam(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
@ -251,7 +251,8 @@ class TestMailActivityTeam(SavepointCase):
partner_record = self.employee.partner_id.with_user(self.employee.id)
self.env.ref("mail.mail_activity_data_call").default_team_id = self.team2
activity = partner_record.activity_schedule(
act_type_xmlid="mail.mail_activity_data_call", user_id=self.employee2.id,
act_type_xmlid="mail.mail_activity_data_call",
user_id=self.employee2.id,
)
self.assertEqual(activity.team_id, self.team2)
self.assertEqual(activity.user_id, self.employee2)
@ -262,7 +263,9 @@ class TestMailActivityTeam(SavepointCase):
partner_record = self.employee.partner_id.with_user(self.employee.id)
self.activity2.default_team_id = self.team2
self.team2.member_ids = self.employee2
activity = partner_record.activity_schedule(activity_type_id=self.activity2.id,)
activity = partner_record.activity_schedule(
activity_type_id=self.activity2.id,
)
self.assertEqual(activity.team_id, self.team2)
self.assertEqual(activity.user_id, self.employee2)
@ -270,7 +273,7 @@ class TestMailActivityTeam(SavepointCase):
res = (
self.env["res.users"]
.with_user(self.employee.id)
.with_context({"team_activities": True})
.with_context(**{"team_activities": True})
.systray_get_activities()
)
self.assertEqual(res[0]["total_count"], 0)
@ -284,7 +287,7 @@ class TestMailActivityTeam(SavepointCase):
res = (
self.env["res.users"]
.with_user(self.employee.id)
.with_context({"team_activities": True})
.with_context(**{"team_activities": True})
.systray_get_activities()
)
self.assertEqual(res[0]["total_count"], 1)
@ -296,8 +299,7 @@ class TestMailActivityTeam(SavepointCase):
self.activity1.write(
{
"default_team_id": self.team1.id,
"default_next_type_id": self.activity2.id,
"force_next": True,
"triggered_next_type_id": self.activity2.id,
}
)
self.activity2.default_team_id = self.team2