[IMP] mail_optional_follower_notification: black, isort
This commit is contained in:
parent
7ea0295439
commit
cedbe63549
@ -3,16 +3,11 @@
|
||||
{
|
||||
"name": "Mail optional follower notification",
|
||||
"summary": "Choose to notify followers on mail.compose.message",
|
||||
"author": "ACSONE SA/NV,"
|
||||
"Odoo Community Association (OCA)",
|
||||
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/social",
|
||||
"category": "Social Network",
|
||||
"version": "12.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"depends": [
|
||||
"mail",
|
||||
],
|
||||
"data": [
|
||||
"wizard/mail_compose_message_view.xml",
|
||||
],
|
||||
"depends": ["mail"],
|
||||
"data": ["wizard/mail_compose_message_view.xml"],
|
||||
}
|
||||
|
@ -1,32 +1,43 @@
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, api
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class MailMessage(models.Model):
|
||||
_inherit = 'mail.message'
|
||||
_inherit = "mail.message"
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
ctx = self.env.context.copy()
|
||||
if not ctx.get('notify_followers') and values.get('partner_ids'):
|
||||
if not ctx.get("notify_followers") and values.get("partner_ids"):
|
||||
partner_list = self.resolve_2many_commands(
|
||||
'partner_ids', values.get('partner_ids'), fields=['id'])
|
||||
ctx['force_partners_to_notify'] = [d['id'] for d in partner_list]
|
||||
"partner_ids", values.get("partner_ids"), fields=["id"]
|
||||
)
|
||||
ctx["force_partners_to_notify"] = [d["id"] for d in partner_list]
|
||||
return super(MailMessage, self.with_context(ctx)).create(values)
|
||||
|
||||
@api.multi
|
||||
def _notify(self, record, msg_vals, force_send=False,
|
||||
send_after_commit=True, model_description=False,
|
||||
mail_auto_delete=True):
|
||||
def _notify(
|
||||
self,
|
||||
record,
|
||||
msg_vals,
|
||||
force_send=False,
|
||||
send_after_commit=True,
|
||||
model_description=False,
|
||||
mail_auto_delete=True,
|
||||
):
|
||||
res = super()._notify(
|
||||
record, msg_vals, force_send=force_send,
|
||||
record,
|
||||
msg_vals,
|
||||
force_send=force_send,
|
||||
send_after_commit=send_after_commit,
|
||||
model_description=model_description,
|
||||
mail_auto_delete=mail_auto_delete)
|
||||
if self.env.context.get('force_partners_to_notify'):
|
||||
mail_auto_delete=mail_auto_delete,
|
||||
)
|
||||
if self.env.context.get("force_partners_to_notify"):
|
||||
# Needaction only for recipients
|
||||
self.needaction_partner_ids = [
|
||||
(6, 0, self.env.context.get('force_partners_to_notify'))]
|
||||
(6, 0, self.env.context.get("force_partners_to_notify"))
|
||||
]
|
||||
return res
|
||||
|
@ -1,22 +1,32 @@
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, api
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_inherit = "res.partner"
|
||||
|
||||
@api.model
|
||||
def _notify(self, message, rdata, record, force_send=False,
|
||||
send_after_commit=True, model_description=False,
|
||||
mail_auto_delete=True):
|
||||
if self.env.context.get('force_partners_to_notify'):
|
||||
partners_to_notify =\
|
||||
self.env.context.get('force_partners_to_notify')
|
||||
def _notify(
|
||||
self,
|
||||
message,
|
||||
rdata,
|
||||
record,
|
||||
force_send=False,
|
||||
send_after_commit=True,
|
||||
model_description=False,
|
||||
mail_auto_delete=True,
|
||||
):
|
||||
if self.env.context.get("force_partners_to_notify"):
|
||||
partners_to_notify = self.env.context.get("force_partners_to_notify")
|
||||
record = self.filtered(lambda p: p.id in partners_to_notify)
|
||||
return super()._notify(
|
||||
message, rdata, record,
|
||||
force_send=force_send, send_after_commit=send_after_commit,
|
||||
message,
|
||||
rdata,
|
||||
record,
|
||||
force_send=force_send,
|
||||
send_after_commit=send_after_commit,
|
||||
model_description=model_description,
|
||||
mail_auto_delete=mail_auto_delete)
|
||||
mail_auto_delete=mail_auto_delete,
|
||||
)
|
||||
|
@ -5,53 +5,55 @@ from odoo.tests import common
|
||||
|
||||
|
||||
class TestMailOptionalFollowernotifications(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.partner_obj = self.env['res.partner']
|
||||
self.partner_01 = self.env.ref('base.res_partner_2')
|
||||
self.demo_user = self.env.ref('base.user_demo')
|
||||
self.partner_obj = self.env["res.partner"]
|
||||
self.partner_01 = self.env.ref("base.res_partner_2")
|
||||
self.demo_user = self.env.ref("base.user_demo")
|
||||
self.partner_03 = self.demo_user.copy().partner_id
|
||||
|
||||
def test_send_email_optional_follower_notifications(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']
|
||||
self.partner_01.message_subscribe(
|
||||
partner_ids=[self.demo_user.partner_id.id])
|
||||
values = mail_compose.with_context(ctx)\
|
||||
.onchange_template_id(False, 'comment', 'res.partner',
|
||||
self.partner_01.id)['value']
|
||||
values['partner_ids'] = [(4, self.demo_user.partner_id.id),
|
||||
(4, self.partner_03.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"]
|
||||
self.partner_01.message_subscribe(partner_ids=[self.demo_user.partner_id.id])
|
||||
values = mail_compose.with_context(ctx).onchange_template_id(
|
||||
False, "comment", "res.partner", self.partner_01.id
|
||||
)["value"]
|
||||
values["partner_ids"] = [
|
||||
(4, self.demo_user.partner_id.id),
|
||||
(4, self.partner_03.id),
|
||||
]
|
||||
compose_id = mail_compose.with_context(ctx).create(values)
|
||||
compose_id.with_context(ctx).send_mail()
|
||||
res = self.env["mail.message"].search(
|
||||
[('model', '=', 'res.partner'),
|
||||
('res_id', '=', self.partner_01.id)])
|
||||
[("model", "=", "res.partner"), ("res_id", "=", self.partner_01.id)]
|
||||
)
|
||||
self.assertEqual(len(res.ids), 1)
|
||||
message = self.env['mail.message']
|
||||
message = self.env["mail.message"]
|
||||
for record in res:
|
||||
if record.notification_ids.mapped('res_partner_id').ids == \
|
||||
[self.partner_03.id] and \
|
||||
record.partner_ids.ids == [self.partner_03.id]:
|
||||
if record.notification_ids.mapped("res_partner_id").ids == [
|
||||
self.partner_03.id
|
||||
] and record.partner_ids.ids == [self.partner_03.id]:
|
||||
message += record
|
||||
self.assertEqual(len(message.ids), 0)
|
||||
values['partner_ids'] = [(6, 0, [self.partner_03.id])]
|
||||
values["partner_ids"] = [(6, 0, [self.partner_03.id])]
|
||||
compose_id = mail_compose.with_context(ctx).create(values)
|
||||
compose_id.notify_followers = False
|
||||
compose_id.with_context(ctx).send_mail()
|
||||
res = self.env["mail.message"].search(
|
||||
[('model', '=', 'res.partner'),
|
||||
('res_id', '=', self.partner_01.id)])
|
||||
message = self.env['mail.message']
|
||||
[("model", "=", "res.partner"), ("res_id", "=", self.partner_01.id)]
|
||||
)
|
||||
message = self.env["mail.message"]
|
||||
for record in res:
|
||||
if record.notification_ids.mapped('res_partner_id').ids == \
|
||||
[self.partner_03.id] and\
|
||||
record.partner_ids.ids == [self.partner_03.id]:
|
||||
if record.notification_ids.mapped("res_partner_id").ids == [
|
||||
self.partner_03.id
|
||||
] and record.partner_ids.ids == [self.partner_03.id]:
|
||||
message += record
|
||||
self.assertEqual(len(message.ids), 1)
|
||||
|
@ -1,11 +1,11 @@
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MailComposeMessage(models.TransientModel):
|
||||
_inherit = 'mail.compose.message'
|
||||
_inherit = "mail.compose.message"
|
||||
|
||||
notify_followers = fields.Boolean(default=True)
|
||||
|
||||
@ -13,8 +13,7 @@ class MailComposeMessage(models.TransientModel):
|
||||
def send_mail(self, auto_commit=False):
|
||||
ctx = self.env.context.copy()
|
||||
for wizard in self:
|
||||
ctx['notify_followers'] = wizard.notify_followers
|
||||
ctx["notify_followers"] = wizard.notify_followers
|
||||
wizard = wizard.with_context(ctx)
|
||||
super(MailComposeMessage, wizard).send_mail(
|
||||
auto_commit=auto_commit)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
super(MailComposeMessage, wizard).send_mail(auto_commit=auto_commit)
|
||||
return {"type": "ir.actions.act_window_close"}
|
||||
|
Loading…
Reference in New Issue
Block a user