2018-11-02 10:38:21 +01:00
|
|
|
# Copyright 2018 David Juaneda - <djuaneda@sdi.es>
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
from odoo.tests.common import TransactionCase
|
|
|
|
|
|
|
|
|
|
|
|
class TestMailActivityBoardMethods(TransactionCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestMailActivityBoardMethods, self).setUp()
|
|
|
|
# Set up activities
|
|
|
|
|
|
|
|
# Create a user as 'Crm Salesman' and added few groups
|
2021-11-17 09:00:11 +01:00
|
|
|
mail_activity_group = self.create_mail_activity_group()
|
2019-10-23 12:19:26 +02:00
|
|
|
self.employee = self.env["res.users"].create(
|
|
|
|
{
|
|
|
|
"company_id": self.env.ref("base.main_company").id,
|
|
|
|
"name": "Employee",
|
|
|
|
"login": "csu",
|
|
|
|
"email": "crmuser@yourcompany.com",
|
2021-11-17 09:00:11 +01:00
|
|
|
"groups_id": [
|
|
|
|
(
|
|
|
|
6,
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
self.env.ref("base.group_user").id,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
2019-10-23 12:19:26 +02:00
|
|
|
}
|
|
|
|
)
|
2018-11-02 10:38:21 +01:00
|
|
|
|
2018-11-30 13:21:01 +01:00
|
|
|
# Create a user who doesn't have access to anything except activities
|
2021-11-17 09:00:11 +01:00
|
|
|
|
2019-10-23 12:19:26 +02:00
|
|
|
self.employee2 = self.env["res.users"].create(
|
|
|
|
{
|
|
|
|
"company_id": self.env.ref("base.main_company").id,
|
|
|
|
"name": "Employee2",
|
|
|
|
"login": "alien",
|
|
|
|
"email": "alien@yourcompany.com",
|
|
|
|
"groups_id": [(6, 0, [mail_activity_group.id])],
|
|
|
|
}
|
|
|
|
)
|
2018-11-30 13:21:01 +01:00
|
|
|
|
2018-11-02 10:38:21 +01:00
|
|
|
# lead_model_id = self.env['ir.model']._get('crm.lead').id
|
2021-11-17 09:00:11 +01:00
|
|
|
partner_model = self.env["ir.model"]._get("res.partner")
|
2019-10-23 12:19:26 +02:00
|
|
|
|
|
|
|
ActivityType = self.env["mail.activity.type"]
|
|
|
|
self.activity1 = ActivityType.create(
|
|
|
|
{
|
|
|
|
"name": "Initial Contact",
|
|
|
|
"delay_count": 5,
|
|
|
|
"delay_unit": "days",
|
|
|
|
"summary": "ACT 1 : Presentation, barbecue, ... ",
|
2021-11-17 09:00:11 +01:00
|
|
|
"res_model": partner_model.model,
|
2019-10-23 12:19:26 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
self.activity2 = ActivityType.create(
|
|
|
|
{
|
|
|
|
"name": "Call for Demo",
|
|
|
|
"delay_count": 6,
|
|
|
|
"delay_unit": "days",
|
|
|
|
"summary": "ACT 2 : I want to show you my ERP !",
|
2021-11-17 09:00:11 +01:00
|
|
|
"res_model": partner_model.model,
|
2019-10-23 12:19:26 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
self.activity3 = ActivityType.create(
|
|
|
|
{
|
|
|
|
"name": "Celebrate the sale",
|
|
|
|
"delay_count": 3,
|
|
|
|
"delay_unit": "days",
|
|
|
|
"summary": "ACT 3 : "
|
|
|
|
"Beers for everyone because I am a good salesman !",
|
2021-11-17 09:00:11 +01:00
|
|
|
"res_model": partner_model.model,
|
2019-10-23 12:19:26 +02:00
|
|
|
}
|
|
|
|
)
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
# I create an opportunity, as employee
|
|
|
|
self.partner_client = self.env.ref("base.res_partner_1")
|
|
|
|
|
2018-11-30 13:21:01 +01:00
|
|
|
# assure there isn't any mail activity yet
|
2019-10-23 12:19:26 +02:00
|
|
|
self.env["mail.activity"].sudo().search([]).unlink()
|
|
|
|
|
|
|
|
self.act1 = (
|
|
|
|
self.env["mail.activity"]
|
|
|
|
.sudo()
|
|
|
|
.create(
|
|
|
|
{
|
|
|
|
"activity_type_id": self.activity3.id,
|
|
|
|
"note": "Partner activity 1.",
|
|
|
|
"res_id": self.partner_client.id,
|
2021-11-17 09:00:11 +01:00
|
|
|
"res_model_id": partner_model.id,
|
2019-10-23 12:19:26 +02:00
|
|
|
"user_id": self.employee.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.act2 = (
|
|
|
|
self.env["mail.activity"]
|
|
|
|
.sudo()
|
|
|
|
.create(
|
|
|
|
{
|
|
|
|
"activity_type_id": self.activity2.id,
|
|
|
|
"note": "Partner activity 2.",
|
|
|
|
"res_id": self.partner_client.id,
|
2021-11-17 09:00:11 +01:00
|
|
|
"res_model_id": partner_model.id,
|
2019-10-23 12:19:26 +02:00
|
|
|
"user_id": self.employee.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.act3 = (
|
|
|
|
self.env["mail.activity"]
|
|
|
|
.sudo()
|
|
|
|
.create(
|
|
|
|
{
|
|
|
|
"activity_type_id": self.activity3.id,
|
|
|
|
"note": "Partner activity 3.",
|
|
|
|
"res_id": self.partner_client.id,
|
2021-11-17 09:00:11 +01:00
|
|
|
"res_model_id": partner_model.id,
|
2019-10-23 12:19:26 +02:00
|
|
|
"user_id": self.employee.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2018-11-02 10:38:21 +01:00
|
|
|
|
2018-11-30 13:21:01 +01:00
|
|
|
def create_mail_activity_group(self):
|
2019-10-23 12:19:26 +02:00
|
|
|
manager_mail_activity_test_group = self.env["res.groups"].create(
|
|
|
|
{"name": "group_manager_mail_activity_test"}
|
|
|
|
)
|
|
|
|
mail_activity_model_id = (
|
|
|
|
self.env["ir.model"]
|
|
|
|
.sudo()
|
|
|
|
.search([("model", "=", "mail.activity")], limit=1)
|
|
|
|
)
|
|
|
|
access = self.env["ir.model.access"].create(
|
|
|
|
{
|
|
|
|
"name": "full_access_mail_activity",
|
|
|
|
"model_id": mail_activity_model_id.id,
|
|
|
|
"perm_read": True,
|
|
|
|
"perm_write": True,
|
|
|
|
"perm_create": True,
|
|
|
|
"perm_unlink": True,
|
|
|
|
}
|
|
|
|
)
|
2018-11-30 13:21:01 +01:00
|
|
|
access.group_id = manager_mail_activity_test_group
|
|
|
|
return manager_mail_activity_test_group
|
|
|
|
|
2018-11-02 10:38:21 +01:00
|
|
|
def get_view(self, activity):
|
|
|
|
action = activity.open_origin()
|
2022-11-11 19:22:39 +01:00
|
|
|
result = self.env[action.get("res_model")].get_views(action.get("views"))
|
|
|
|
return result.get("views").get(action.get("view_mode"))
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
def test_open_origin_res_partner(self):
|
2021-01-22 08:49:08 +01:00
|
|
|
"""This test case checks
|
|
|
|
- If the method redirects to the form view of the correct one
|
|
|
|
of an object of the 'res.partner' class to which the activity
|
|
|
|
belongs.
|
2018-11-02 10:38:21 +01:00
|
|
|
"""
|
|
|
|
# Id of the form view for the class 'crm.lead', type 'lead'
|
2019-10-23 12:19:26 +02:00
|
|
|
form_view_partner_id = self.env.ref("base.view_partner_form").id
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
# Id of the form view return open_origin()
|
|
|
|
view = self.get_view(self.act1)
|
|
|
|
|
|
|
|
# Check the next view is correct
|
2022-11-11 19:22:39 +01:00
|
|
|
self.assertEqual(form_view_partner_id, view.get("id"))
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
# Id of the form view return open_origin()
|
|
|
|
view = self.get_view(self.act2)
|
|
|
|
|
|
|
|
# Check the next view is correct
|
2022-11-11 19:22:39 +01:00
|
|
|
self.assertEqual(form_view_partner_id, view.get("id"))
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
# Id of the form view return open_origin()
|
|
|
|
view = self.get_view(self.act3)
|
|
|
|
|
|
|
|
# Check the next view is correct
|
2022-11-11 19:22:39 +01:00
|
|
|
self.assertEqual(form_view_partner_id, view.get("id"))
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
def test_redirect_to_activities(self):
|
2021-01-22 08:49:08 +01:00
|
|
|
"""This test case checks
|
|
|
|
- if the method returns the correct action,
|
|
|
|
- if the correct activities are shown.
|
2018-11-02 10:38:21 +01:00
|
|
|
"""
|
2019-10-23 12:19:26 +02:00
|
|
|
action_id = self.env.ref("mail_activity_board.open_boards_activities").id
|
|
|
|
action = self.partner_client.redirect_to_activities(
|
2022-11-11 19:22:39 +01:00
|
|
|
**{
|
|
|
|
"id": self.partner_client.id,
|
|
|
|
"model": self.partner_client._name,
|
|
|
|
}
|
2019-10-23 12:19:26 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(action.get("id"), action_id)
|
|
|
|
|
|
|
|
kwargs = {"groupby": ["activity_type_id"]}
|
|
|
|
kwargs["domain"] = action.get("domain")
|
|
|
|
|
2022-11-11 19:22:39 +01:00
|
|
|
result = self.env[action.get("res_model")].get_views(action.get("views"))
|
|
|
|
# fields = result.get("views").get("kanban").get("fields")
|
|
|
|
fields = result.get("models").get(action.get("res_model"))
|
2019-10-23 12:19:26 +02:00
|
|
|
kwargs["fields"] = list(fields.keys())
|
|
|
|
|
|
|
|
result = self.env["mail.activity"].read_group(**kwargs)
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
acts = []
|
|
|
|
for group in result:
|
2019-10-23 12:19:26 +02:00
|
|
|
records = self.env["mail.activity"].search_read(
|
|
|
|
domain=group.get("__domain"), fields=kwargs["fields"]
|
2018-11-02 10:38:21 +01:00
|
|
|
)
|
2019-10-23 12:19:26 +02:00
|
|
|
acts += [record_id.get("id") for record_id in records]
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
for act in acts:
|
|
|
|
self.assertIn(act, self.partner_client.activity_ids.ids)
|
2019-12-03 14:29:08 +01:00
|
|
|
|
|
|
|
def test_related_model_instance(self):
|
|
|
|
"""This test case checks the direct access from the activity to the
|
|
|
|
linked model instance
|
|
|
|
"""
|
|
|
|
self.assertEqual(self.act3.related_model_instance, self.partner_client)
|
|
|
|
self.act3.write({"res_id": False, "res_model": False})
|
|
|
|
self.assertFalse(self.act3.related_model_instance)
|