[IMP] mail_activity_partner: black, isort

This commit is contained in:
Adrià Gil Sorribes 2019-12-24 10:56:16 +01:00 committed by Joan Mateu Jordi
parent c2848acc24
commit a0374eae05
3 changed files with 99 additions and 80 deletions

View File

@ -1,20 +1,15 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Mail Activity Partner',
'summary': 'Add Partner to Activities',
'version': '12.0.1.0.0',
'development_status': 'Beta',
'category': 'Social Network',
'website': 'https://github.com/OCA/social',
'author': 'Eficent, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'installable': True,
'data': [
'views/mail_activity_views.xml',
],
'depends': [
'mail_activity_board',
],
"name": "Mail Activity Partner",
"summary": "Add Partner to Activities",
"version": "12.0.1.0.0",
"development_status": "Beta",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": "Eficent, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"data": ["views/mail_activity_views.xml"],
"depends": ["mail_activity_board"],
}

View File

@ -1,36 +1,36 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# 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):
_inherit = 'mail.activity'
_inherit = "mail.activity"
partner_id = fields.Many2one(
comodel_name='res.partner',
comodel_name="res.partner",
index=True,
compute='_compute_res_partner_id',
compute="_compute_res_partner_id",
store=True,
)
commercial_partner_id = fields.Many2one(
related='partner_id.commercial_partner_id',
string='Commercial Entity',
related="partner_id.commercial_partner_id",
string="Commercial Entity",
store=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):
for obj in self:
res_model = obj.res_model
res_id = obj.res_id
if res_model == 'res.partner':
if res_model == "res.partner":
obj.partner_id = res_id
else:
res_model_id = obj.env[res_model].search([('id', '=', res_id)])
if 'partner_id' in res_model_id._fields and \
res_model_id.partner_id:
res_model_id = obj.env[res_model].search([("id", "=", res_id)])
if "partner_id" in res_model_id._fields and res_model_id.partner_id:
obj.partner_id = res_model_id.partner_id
else:
obj.partner_id = None

View File

@ -4,72 +4,96 @@ from odoo.tests.common import TransactionCase
class TestMailActivityPartner(TransactionCase):
def setUp(self):
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({
'company_id': self.env.ref("base.main_company").id,
'name': "Employee",
'login': "csu",
'email': "crmuser@yourcompany.com",
'groups_id': [(6, 0, [
self.env.ref('base.group_user').id,
self.env.ref('base.group_partner_manager').id])]
})
self.employee = self.env["res.users"].create(
{
"company_id": self.env.ref("base.main_company").id,
"name": "Employee",
"login": "csu",
"email": "crmuser@yourcompany.com",
"groups_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']
self.activity1 = activity_type_model.create({
'name': 'Initial Contact',
'days': 5,
'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,
'summary': 'ACT 2 : I want to show you my ERP !',
'res_model_id': self.partner_ir_model.id,
})
activity_type_model = self.env["mail.activity.type"]
self.activity1 = activity_type_model.create(
{
"name": "Initial Contact",
"days": 5,
"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,
"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({
'name': 'Homer Simpson',
'city': 'Springfield',
'street': '742 Evergreen Terrace',
'street2': 'Donut Lane',
'street3': 'Tho',
})
self.homer = self.env["res.partner"].create(
{
"name": "Homer Simpson",
"city": "Springfield",
"street": "742 Evergreen Terrace",
"street2": "Donut Lane",
"street3": "Tho",
}
)
# test synchro of street3 on create
self.partner_10 = self.env['res.partner'].create({
'name': 'Bart Simpson',
'parent_id': self.homer.id,
'type': 'contact',
})
self.partner_10 = self.env["res.partner"].create(
{"name": "Bart Simpson", "parent_id": self.homer.id, "type": "contact"}
)
def test_partner_for_activity(self):
self.act1 = self.env['mail.activity'].sudo().create({
'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.act1 = (
self.env["mail.activity"]
.sudo()
.create(
{
"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({
'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,
})
self.act2 = (
self.env["mail.activity"]
.sudo(self.employee)
.create(
{
"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
self.assertEqual(self.act1.partner_id, self.partner_01)