[REF] mail_optional_autofollow: Black python code
This commit is contained in:
parent
8961f1fba2
commit
2f63d7ba9e
@ -1,21 +1,16 @@
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
'name': "Mail optional autofollow",
|
||||
'summary': """
|
||||
"name": "Mail optional autofollow",
|
||||
"summary": """
|
||||
Choose if you want to automatically add new recipients as followers
|
||||
on mail.compose.message""",
|
||||
'author': 'ACSONE SA/NV,'
|
||||
'Odoo Community Association (OCA)',
|
||||
'website': "http://acsone.eu",
|
||||
'category': 'Social Network',
|
||||
'version': '11.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'depends': [
|
||||
'mail',
|
||||
],
|
||||
'data': [
|
||||
'wizard/mail_compose_message_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
|
||||
"website": "http://acsone.eu",
|
||||
"category": "Social Network",
|
||||
"version": "11.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["mail",],
|
||||
"data": ["wizard/mail_compose_message_view.xml",],
|
||||
"installable": True,
|
||||
}
|
||||
|
@ -5,40 +5,47 @@ from odoo.tests import common
|
||||
|
||||
|
||||
class TestAttachExistingAttachment(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAttachExistingAttachment, self).setUp()
|
||||
self.partner_obj = self.env['res.partner']
|
||||
self.partner_01 = self.env.ref('base.res_partner_10')
|
||||
self.partner_02 = self.env.ref('base.res_partner_address_17')
|
||||
self.partner_obj = self.env["res.partner"]
|
||||
self.partner_01 = self.env.ref("base.res_partner_10")
|
||||
self.partner_02 = self.env.ref("base.res_partner_address_17")
|
||||
|
||||
def test_send_email_attachment(self):
|
||||
ctx = self.env.context.copy()
|
||||
ctx.update({
|
||||
'default_model': 'res.partner',
|
||||
'default_res_id': self.partner_01.id,
|
||||
'default_composition_mode': 'comment',
|
||||
})
|
||||
mail_compose = self.env['mail.compose.message']
|
||||
values = mail_compose.with_context(ctx)\
|
||||
.onchange_template_id(False, 'comment', 'res.partner',
|
||||
self.partner_01.id)['value']
|
||||
values['partner_ids'] = [(4, self.partner_02.id)]
|
||||
ctx.update(
|
||||
{
|
||||
"default_model": "res.partner",
|
||||
"default_res_id": self.partner_01.id,
|
||||
"default_composition_mode": "comment",
|
||||
}
|
||||
)
|
||||
mail_compose = self.env["mail.compose.message"]
|
||||
values = mail_compose.with_context(ctx).onchange_template_id(
|
||||
False, "comment", "res.partner", self.partner_01.id
|
||||
)["value"]
|
||||
values["partner_ids"] = [(4, self.partner_02.id)]
|
||||
compose_id = mail_compose.with_context(ctx).create(values)
|
||||
compose_id.autofollow_recipients = False
|
||||
compose_id.with_context(ctx).send_mail()
|
||||
res = self.env["mail.followers"].search(
|
||||
[('res_model', '=', 'res.partner'),
|
||||
('res_id', '=', self.partner_01.id),
|
||||
('partner_id', '=', self.partner_02.id)])
|
||||
[
|
||||
("res_model", "=", "res.partner"),
|
||||
("res_id", "=", self.partner_01.id),
|
||||
("partner_id", "=", self.partner_02.id),
|
||||
]
|
||||
)
|
||||
# I check if the recipient isn't a follower
|
||||
self.assertEqual(len(res.ids), 0)
|
||||
compose_id = mail_compose.with_context(ctx).create(values)
|
||||
compose_id.autofollow_recipients = True
|
||||
compose_id.with_context(ctx).send_mail()
|
||||
res = self.env["mail.followers"].search(
|
||||
[('res_model', '=', 'res.partner'),
|
||||
('res_id', '=', self.partner_01.id),
|
||||
('partner_id', '=', self.partner_02.id)])
|
||||
[
|
||||
("res_model", "=", "res.partner"),
|
||||
("res_id", "=", self.partner_01.id),
|
||||
("partner_id", "=", self.partner_02.id),
|
||||
]
|
||||
)
|
||||
# I check if the recipient is a follower
|
||||
self.assertEqual(len(res.ids), 1)
|
||||
|
@ -1,29 +1,31 @@
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models, fields, api
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MailComposeMessage(models.TransientModel):
|
||||
_inherit = 'mail.compose.message'
|
||||
_inherit = "mail.compose.message"
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(MailComposeMessage, self).default_get(fields_list)
|
||||
res.setdefault(
|
||||
'autofollow_recipients',
|
||||
self.env.context.get('mail_post_autofollow', False))
|
||||
"autofollow_recipients", self.env.context.get("mail_post_autofollow", False)
|
||||
)
|
||||
return res
|
||||
|
||||
autofollow_recipients = fields.Boolean(
|
||||
string='Make recipients followers',
|
||||
string="Make recipients followers",
|
||||
help="""if checked, the additional recipients will be added as\
|
||||
followers on the related object""")
|
||||
followers on the related object""",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def send_mail(self, auto_commit=False):
|
||||
for wizard in self:
|
||||
super(MailComposeMessage, wizard.with_context(
|
||||
mail_post_autofollow=wizard.autofollow_recipients)).send_mail(
|
||||
auto_commit=auto_commit)
|
||||
super(
|
||||
MailComposeMessage,
|
||||
wizard.with_context(mail_post_autofollow=wizard.autofollow_recipients),
|
||||
).send_mail(auto_commit=auto_commit)
|
||||
return True
|
||||
|
@ -10,4 +10,4 @@
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
Loading…
Reference in New Issue
Block a user