[IMP] mail_activity_partner: black, isort
This commit is contained in:
parent
c2848acc24
commit
a0374eae05
@ -1,20 +1,15 @@
|
|||||||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
|
# Copyright 2018 Eficent Business and IT Consulting Services, 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).
|
||||||
{
|
{
|
||||||
'name': 'Mail Activity Partner',
|
"name": "Mail Activity Partner",
|
||||||
'summary': 'Add Partner to Activities',
|
"summary": "Add Partner to Activities",
|
||||||
'version': '12.0.1.0.0',
|
"version": "12.0.1.0.0",
|
||||||
'development_status': 'Beta',
|
"development_status": "Beta",
|
||||||
'category': 'Social Network',
|
"category": "Social Network",
|
||||||
'website': 'https://github.com/OCA/social',
|
"website": "https://github.com/OCA/social",
|
||||||
'author': 'Eficent, Odoo Community Association (OCA)',
|
"author": "Eficent, Odoo Community Association (OCA)",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'installable': True,
|
"installable": True,
|
||||||
'data': [
|
"data": ["views/mail_activity_views.xml"],
|
||||||
'views/mail_activity_views.xml',
|
"depends": ["mail_activity_board"],
|
||||||
],
|
|
||||||
'depends': [
|
|
||||||
'mail_activity_board',
|
|
||||||
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
|
# Copyright 2018 Eficent Business and IT Consulting Services, 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).
|
||||||
from odoo import api, models, fields
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class MailActivity(models.Model):
|
class MailActivity(models.Model):
|
||||||
_inherit = 'mail.activity'
|
_inherit = "mail.activity"
|
||||||
|
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
comodel_name='res.partner',
|
comodel_name="res.partner",
|
||||||
index=True,
|
index=True,
|
||||||
compute='_compute_res_partner_id',
|
compute="_compute_res_partner_id",
|
||||||
store=True,
|
store=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
commercial_partner_id = fields.Many2one(
|
commercial_partner_id = fields.Many2one(
|
||||||
related='partner_id.commercial_partner_id',
|
related="partner_id.commercial_partner_id",
|
||||||
string='Commercial Entity',
|
string="Commercial Entity",
|
||||||
store=True,
|
store=True,
|
||||||
related_sudo=True,
|
related_sudo=True,
|
||||||
readonly=True)
|
readonly=True,
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends('res_model', 'res_id')
|
@api.depends("res_model", "res_id")
|
||||||
def _compute_res_partner_id(self):
|
def _compute_res_partner_id(self):
|
||||||
for obj in self:
|
for obj in self:
|
||||||
res_model = obj.res_model
|
res_model = obj.res_model
|
||||||
res_id = obj.res_id
|
res_id = obj.res_id
|
||||||
if res_model == 'res.partner':
|
if res_model == "res.partner":
|
||||||
obj.partner_id = res_id
|
obj.partner_id = res_id
|
||||||
else:
|
else:
|
||||||
res_model_id = obj.env[res_model].search([('id', '=', res_id)])
|
res_model_id = obj.env[res_model].search([("id", "=", res_id)])
|
||||||
if 'partner_id' in res_model_id._fields and \
|
if "partner_id" in res_model_id._fields and res_model_id.partner_id:
|
||||||
res_model_id.partner_id:
|
|
||||||
obj.partner_id = res_model_id.partner_id
|
obj.partner_id = res_model_id.partner_id
|
||||||
else:
|
else:
|
||||||
obj.partner_id = None
|
obj.partner_id = None
|
||||||
|
@ -4,72 +4,96 @@ from odoo.tests.common import TransactionCase
|
|||||||
|
|
||||||
|
|
||||||
class TestMailActivityPartner(TransactionCase):
|
class TestMailActivityPartner(TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestMailActivityPartner, self).setUp()
|
super(TestMailActivityPartner, self).setUp()
|
||||||
|
|
||||||
self.user_admin = self.env.ref('base.user_root')
|
self.user_admin = self.env.ref("base.user_root")
|
||||||
|
|
||||||
self.employee = self.env['res.users'].create({
|
self.employee = self.env["res.users"].create(
|
||||||
'company_id': self.env.ref("base.main_company").id,
|
{
|
||||||
'name': "Employee",
|
"company_id": self.env.ref("base.main_company").id,
|
||||||
'login': "csu",
|
"name": "Employee",
|
||||||
'email': "crmuser@yourcompany.com",
|
"login": "csu",
|
||||||
'groups_id': [(6, 0, [
|
"email": "crmuser@yourcompany.com",
|
||||||
self.env.ref('base.group_user').id,
|
"groups_id": [
|
||||||
self.env.ref('base.group_partner_manager').id])]
|
(
|
||||||
})
|
6,
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
self.env.ref("base.group_user").id,
|
||||||
|
self.env.ref("base.group_partner_manager").id,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.partner_ir_model = self.env['ir.model']._get('res.partner')
|
self.partner_ir_model = self.env["ir.model"]._get("res.partner")
|
||||||
|
|
||||||
activity_type_model = self.env['mail.activity.type']
|
activity_type_model = self.env["mail.activity.type"]
|
||||||
self.activity1 = activity_type_model.create({
|
self.activity1 = activity_type_model.create(
|
||||||
'name': 'Initial Contact',
|
{
|
||||||
'days': 5,
|
"name": "Initial Contact",
|
||||||
'summary': 'ACT 1 : Presentation, barbecue, ... ',
|
"days": 5,
|
||||||
'res_model_id': self.partner_ir_model.id,
|
"summary": "ACT 1 : Presentation, barbecue, ... ",
|
||||||
})
|
"res_model_id": self.partner_ir_model.id,
|
||||||
self.activity2 = activity_type_model.create({
|
}
|
||||||
'name': 'Call for Demo',
|
)
|
||||||
'days': 6,
|
self.activity2 = activity_type_model.create(
|
||||||
'summary': 'ACT 2 : I want to show you my ERP !',
|
{
|
||||||
'res_model_id': self.partner_ir_model.id,
|
"name": "Call for Demo",
|
||||||
})
|
"days": 6,
|
||||||
|
"summary": "ACT 2 : I want to show you my ERP !",
|
||||||
|
"res_model_id": self.partner_ir_model.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.partner_01 = self.env.ref('base.res_partner_1')
|
self.partner_01 = self.env.ref("base.res_partner_1")
|
||||||
|
|
||||||
self.homer = self.env['res.partner'].create({
|
self.homer = self.env["res.partner"].create(
|
||||||
'name': 'Homer Simpson',
|
{
|
||||||
'city': 'Springfield',
|
"name": "Homer Simpson",
|
||||||
'street': '742 Evergreen Terrace',
|
"city": "Springfield",
|
||||||
'street2': 'Donut Lane',
|
"street": "742 Evergreen Terrace",
|
||||||
'street3': 'Tho',
|
"street2": "Donut Lane",
|
||||||
})
|
"street3": "Tho",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# test synchro of street3 on create
|
# test synchro of street3 on create
|
||||||
self.partner_10 = self.env['res.partner'].create({
|
self.partner_10 = self.env["res.partner"].create(
|
||||||
'name': 'Bart Simpson',
|
{"name": "Bart Simpson", "parent_id": self.homer.id, "type": "contact"}
|
||||||
'parent_id': self.homer.id,
|
)
|
||||||
'type': 'contact',
|
|
||||||
})
|
|
||||||
|
|
||||||
def test_partner_for_activity(self):
|
def test_partner_for_activity(self):
|
||||||
|
|
||||||
self.act1 = self.env['mail.activity'].sudo().create({
|
self.act1 = (
|
||||||
'activity_type_id': self.activity1.id,
|
self.env["mail.activity"]
|
||||||
'note': 'Partner activity 1.',
|
.sudo()
|
||||||
'res_id': self.partner_01.id,
|
.create(
|
||||||
'res_model_id': self.partner_ir_model.id,
|
{
|
||||||
'user_id': self.user_admin.id,
|
"activity_type_id": self.activity1.id,
|
||||||
})
|
"note": "Partner activity 1.",
|
||||||
|
"res_id": self.partner_01.id,
|
||||||
|
"res_model_id": self.partner_ir_model.id,
|
||||||
|
"user_id": self.user_admin.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.act2 = self.env['mail.activity'].sudo(self.employee).create({
|
self.act2 = (
|
||||||
'activity_type_id': self.activity2.id,
|
self.env["mail.activity"]
|
||||||
'note': 'Partner activity 10.',
|
.sudo(self.employee)
|
||||||
'res_id': self.partner_10.id,
|
.create(
|
||||||
'res_model_id': self.partner_ir_model.id,
|
{
|
||||||
'user_id': self.employee.id,
|
"activity_type_id": self.activity2.id,
|
||||||
})
|
"note": "Partner activity 10.",
|
||||||
|
"res_id": self.partner_10.id,
|
||||||
|
"res_model_id": self.partner_ir_model.id,
|
||||||
|
"user_id": self.employee.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Check partner_id of created activities
|
# Check partner_id of created activities
|
||||||
self.assertEqual(self.act1.partner_id, self.partner_01)
|
self.assertEqual(self.act1.partner_id, self.partner_01)
|
||||||
|
Loading…
Reference in New Issue
Block a user