2019-12-24 11:57:30 +01:00
|
|
|
# Copyright 2018 ForgeFlow S.L.
|
2018-12-21 11:00:35 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
2021-11-30 09:44:08 +01:00
|
|
|
from odoo.tests.common import TransactionCase
|
2018-12-21 11:00:35 +01:00
|
|
|
|
|
|
|
|
2021-11-30 09:44:08 +01:00
|
|
|
class TestMailActivityPartner(TransactionCase):
|
2019-12-24 11:57:30 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super().setUpClass()
|
|
|
|
# disable tracking test suite wise
|
|
|
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
|
|
|
cls.user_model = cls.env["res.users"].with_context(no_reset_password=True)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.user_admin = cls.env.ref("base.user_root")
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.employee = cls.env["res.users"].create(
|
2019-12-24 10:56:16 +01:00
|
|
|
{
|
2019-12-24 11:57:30 +01:00
|
|
|
"company_id": cls.env.ref("base.main_company").id,
|
2019-12-24 10:56:16 +01:00
|
|
|
"name": "Employee",
|
|
|
|
"login": "csu",
|
|
|
|
"email": "crmuser@yourcompany.com",
|
|
|
|
"groups_id": [
|
|
|
|
(
|
|
|
|
6,
|
|
|
|
0,
|
|
|
|
[
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.env.ref("base.group_user").id,
|
|
|
|
cls.env.ref("base.group_partner_manager").id,
|
2019-12-24 10:56:16 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2021-11-30 09:44:08 +01:00
|
|
|
cls.partner_model = cls.env["ir.model"]._get("res.partner")
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2019-12-24 11:57:30 +01:00
|
|
|
activity_type_model = cls.env["mail.activity.type"]
|
|
|
|
cls.activity1 = activity_type_model.create(
|
2019-12-24 10:56:16 +01:00
|
|
|
{
|
|
|
|
"name": "Initial Contact",
|
2019-12-24 11:57:30 +01:00
|
|
|
"delay_count": 5,
|
2021-11-30 09:44:08 +01:00
|
|
|
"delay_unit": "days",
|
2019-12-24 10:56:16 +01:00
|
|
|
"summary": "ACT 1 : Presentation, barbecue, ... ",
|
2021-11-30 09:44:08 +01:00
|
|
|
"res_model": cls.partner_model.model,
|
2019-12-24 10:56:16 +01:00
|
|
|
}
|
|
|
|
)
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.activity2 = activity_type_model.create(
|
2019-12-24 10:56:16 +01:00
|
|
|
{
|
|
|
|
"name": "Call for Demo",
|
2019-12-24 11:57:30 +01:00
|
|
|
"delay_count": 6,
|
2019-12-24 10:56:16 +01:00
|
|
|
"summary": "ACT 2 : I want to show you my ERP !",
|
2021-11-30 09:44:08 +01:00
|
|
|
"res_model": cls.partner_model.model,
|
2019-12-24 10:56:16 +01:00
|
|
|
}
|
|
|
|
)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.partner_01 = cls.env.ref("base.res_partner_1")
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.homer = cls.env["res.partner"].create(
|
2019-12-24 10:56:16 +01:00
|
|
|
{
|
|
|
|
"name": "Homer Simpson",
|
|
|
|
"city": "Springfield",
|
|
|
|
"street": "742 Evergreen Terrace",
|
|
|
|
"street2": "Donut Lane",
|
|
|
|
}
|
|
|
|
)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
|
|
|
# test synchro of street3 on create
|
2019-12-24 11:57:30 +01:00
|
|
|
cls.partner_10 = cls.env["res.partner"].create(
|
|
|
|
{"name": "Bart Simpson", "parent_id": cls.homer.id, "type": "contact"}
|
2019-12-24 10:56:16 +01:00
|
|
|
)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
|
|
|
def test_partner_for_activity(self):
|
|
|
|
|
2019-12-24 10:56:16 +01:00
|
|
|
self.act1 = (
|
|
|
|
self.env["mail.activity"]
|
|
|
|
.sudo()
|
|
|
|
.create(
|
|
|
|
{
|
|
|
|
"activity_type_id": self.activity1.id,
|
|
|
|
"note": "Partner activity 1.",
|
|
|
|
"res_id": self.partner_01.id,
|
2021-11-30 09:44:08 +01:00
|
|
|
"res_model_id": self.partner_model.id,
|
2019-12-24 10:56:16 +01:00
|
|
|
"user_id": self.user_admin.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
2019-12-24 10:56:16 +01:00
|
|
|
self.act2 = (
|
|
|
|
self.env["mail.activity"]
|
2019-12-24 11:57:30 +01:00
|
|
|
.with_user(self.employee)
|
2019-12-24 10:56:16 +01:00
|
|
|
.create(
|
|
|
|
{
|
|
|
|
"activity_type_id": self.activity2.id,
|
|
|
|
"note": "Partner activity 10.",
|
|
|
|
"res_id": self.partner_10.id,
|
2021-11-30 09:44:08 +01:00
|
|
|
"res_model_id": self.partner_model.id,
|
2019-12-24 10:56:16 +01:00
|
|
|
"user_id": self.employee.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2018-12-21 11:00:35 +01:00
|
|
|
|
|
|
|
# Check partner_id of created activities
|
|
|
|
self.assertEqual(self.act1.partner_id, self.partner_01)
|
|
|
|
self.assertEqual(self.act2.partner_id, self.partner_10)
|
|
|
|
|
|
|
|
# Check commercial_partner_id for created activities
|
|
|
|
self.assertEqual(self.act1.commercial_partner_id, self.partner_01)
|
|
|
|
self.assertEqual(self.act2.commercial_partner_id, self.homer)
|