[IMP] mail_restrict_follower_selection: black, isort
This commit is contained in:
parent
1c713ad24a
commit
347879376f
@ -9,12 +9,7 @@
|
||||
"license": "AGPL-3",
|
||||
"category": "Social Network",
|
||||
"summary": "Define a domain from which followers can be selected",
|
||||
"depends": [
|
||||
'mail',
|
||||
],
|
||||
"data": [
|
||||
"data/ir_config_parameter.xml",
|
||||
"data/ir_actions.xml",
|
||||
],
|
||||
'installable': True,
|
||||
"depends": ["mail"],
|
||||
"data": ["data/ir_config_parameter.xml", "data/ir_actions.xml"],
|
||||
"installable": True,
|
||||
}
|
||||
|
@ -6,23 +6,35 @@ from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class MailFollowers(models.Model):
|
||||
_inherit = 'mail.followers'
|
||||
_inherit = "mail.followers"
|
||||
|
||||
def _add_followers(self, res_model, res_ids, partner_ids, partner_subtypes,
|
||||
channel_ids, channel_subtypes,
|
||||
check_existing=False, existing_policy='skip'):
|
||||
def _add_followers(
|
||||
self,
|
||||
res_model,
|
||||
res_ids,
|
||||
partner_ids,
|
||||
partner_subtypes,
|
||||
channel_ids,
|
||||
channel_subtypes,
|
||||
check_existing=False,
|
||||
existing_policy="skip",
|
||||
):
|
||||
domain = self.env[
|
||||
'mail.wizard.invite'
|
||||
"mail.wizard.invite"
|
||||
]._mail_restrict_follower_selection_get_domain()
|
||||
partners = self.env['res.partner'].search(
|
||||
[('id', 'in', partner_ids)] +
|
||||
safe_eval(domain)
|
||||
partners = self.env["res.partner"].search(
|
||||
[("id", "in", partner_ids)] + safe_eval(domain)
|
||||
)
|
||||
_res_ids = res_ids.copy() or [0]
|
||||
new, update = super()._add_followers(
|
||||
res_model, res_ids, partners.ids, partner_subtypes, channel_ids,
|
||||
channel_subtypes, check_existing=check_existing,
|
||||
existing_policy=existing_policy
|
||||
res_model,
|
||||
res_ids,
|
||||
partners.ids,
|
||||
partner_subtypes,
|
||||
channel_ids,
|
||||
channel_subtypes,
|
||||
check_existing=check_existing,
|
||||
existing_policy=existing_policy,
|
||||
)
|
||||
|
||||
for res_id in _res_ids:
|
||||
|
@ -3,22 +3,24 @@ from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class MailThread(models.AbstractModel):
|
||||
_inherit = 'mail.thread'
|
||||
_inherit = "mail.thread"
|
||||
|
||||
@api.multi
|
||||
def _message_add_suggested_recipient(
|
||||
self, result, partner=None, email=None, reason=''):
|
||||
self, result, partner=None, email=None, reason=""
|
||||
):
|
||||
result = super(MailThread, self)._message_add_suggested_recipient(
|
||||
result, partner=partner, email=email, reason=reason)
|
||||
result, partner=partner, email=email, reason=reason
|
||||
)
|
||||
domain = self.env[
|
||||
'mail.wizard.invite'
|
||||
"mail.wizard.invite"
|
||||
]._mail_restrict_follower_selection_get_domain()
|
||||
eval_domain = safe_eval(domain)
|
||||
for key in result:
|
||||
for partner_id, email, reason in result[key]:
|
||||
if partner_id:
|
||||
partner = self.env['res.partner'].search(
|
||||
[('id', '=', partner_id)] + eval_domain
|
||||
partner = self.env["res.partner"].search(
|
||||
[("id", "=", partner_id)] + eval_domain
|
||||
)
|
||||
if not partner:
|
||||
result[key].remove((partner_id, email, reason))
|
||||
|
@ -3,31 +3,38 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class MailWizardInvite(models.TransientModel):
|
||||
_inherit = 'mail.wizard.invite'
|
||||
_inherit = "mail.wizard.invite"
|
||||
|
||||
@api.model
|
||||
def _mail_restrict_follower_selection_get_domain(self):
|
||||
parameter_name = 'mail_restrict_follower_selection.domain'
|
||||
return self.env['ir.config_parameter'].sudo().get_param(
|
||||
"{0}.{1}".format(parameter_name,
|
||||
self.env.context.get('default_res_model')),
|
||||
self.env['ir.config_parameter'].sudo().get_param(
|
||||
parameter_name, default='[]')
|
||||
parameter_name = "mail_restrict_follower_selection.domain"
|
||||
return (
|
||||
self.env["ir.config_parameter"]
|
||||
.sudo()
|
||||
.get_param(
|
||||
"{}.{}".format(
|
||||
parameter_name, self.env.context.get("default_res_model")
|
||||
),
|
||||
self.env["ir.config_parameter"]
|
||||
.sudo()
|
||||
.get_param(parameter_name, default="[]"),
|
||||
)
|
||||
)
|
||||
|
||||
@api.model
|
||||
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
|
||||
submenu=False):
|
||||
def fields_view_get(
|
||||
self, view_id=None, view_type="form", toolbar=False, submenu=False
|
||||
):
|
||||
result = super(MailWizardInvite, self).fields_view_get(
|
||||
view_id=view_id, view_type=view_type, toolbar=toolbar,
|
||||
submenu=submenu)
|
||||
arch = etree.fromstring(result['arch'])
|
||||
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
|
||||
)
|
||||
arch = etree.fromstring(result["arch"])
|
||||
for field in arch.xpath('//field[@name="partner_ids"]'):
|
||||
field.attrib['domain'] = self\
|
||||
._mail_restrict_follower_selection_get_domain()
|
||||
result['arch'] = etree.tostring(arch)
|
||||
field.attrib["domain"] = self._mail_restrict_follower_selection_get_domain()
|
||||
result["arch"] = etree.tostring(arch)
|
||||
return result
|
||||
|
@ -3,55 +3,59 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestMailRestrictFollowerSelection(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.partner = self.env['res.partner'].create({
|
||||
'name': 'Partner',
|
||||
'customer': True,
|
||||
'email': 'test@test.com',
|
||||
})
|
||||
self.partner = self.env["res.partner"].create(
|
||||
{"name": "Partner", "customer": True, "email": "test@test.com"}
|
||||
)
|
||||
|
||||
def test_fields_view_get(self):
|
||||
result = self.env['mail.wizard.invite'].fields_view_get(
|
||||
view_type='form')
|
||||
for field in etree.fromstring(result['arch']).xpath(
|
||||
'//field[@name="partner_ids"]'):
|
||||
self.assertTrue(field.get('domain'))
|
||||
result = self.env["mail.wizard.invite"].fields_view_get(view_type="form")
|
||||
for field in etree.fromstring(result["arch"]).xpath(
|
||||
'//field[@name="partner_ids"]'
|
||||
):
|
||||
self.assertTrue(field.get("domain"))
|
||||
|
||||
def send_action(self):
|
||||
compose = self.env['mail.compose.message'].with_context({
|
||||
'mail_post_autofollow': True,
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': 'res.partner',
|
||||
'default_use_active_domain': True,
|
||||
}).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.description}',
|
||||
'res_id': self.partner.id,
|
||||
'partner_ids': [(4, id) for id in self.partner.ids],
|
||||
})
|
||||
compose = (
|
||||
self.env["mail.compose.message"]
|
||||
.with_context(
|
||||
{
|
||||
"mail_post_autofollow": True,
|
||||
"default_composition_mode": "comment",
|
||||
"default_model": "res.partner",
|
||||
"default_use_active_domain": True,
|
||||
}
|
||||
)
|
||||
.create(
|
||||
{
|
||||
"subject": "From Composer Test",
|
||||
"body": "${object.description}",
|
||||
"res_id": self.partner.id,
|
||||
"partner_ids": [(4, id) for id in self.partner.ids],
|
||||
}
|
||||
)
|
||||
)
|
||||
self.assertEqual(compose.partner_ids, self.partner)
|
||||
compose.action_send_mail()
|
||||
|
||||
def test_followers_meet(self):
|
||||
self.partner.write({'customer': True})
|
||||
self.partner.write({"customer": True})
|
||||
self.assertTrue(self.partner.customer)
|
||||
self.send_action()
|
||||
self.assertIn(
|
||||
self.partner,
|
||||
self.partner.message_follower_ids.mapped('partner_id')
|
||||
self.partner, self.partner.message_follower_ids.mapped("partner_id")
|
||||
)
|
||||
|
||||
def test_followers_not_meet(self):
|
||||
self.partner.write({'customer': False})
|
||||
self.partner.write({"customer": False})
|
||||
self.assertFalse(self.partner.customer)
|
||||
self.send_action()
|
||||
self.assertNotIn(
|
||||
self.partner,
|
||||
self.partner.message_follower_ids.mapped('partner_id')
|
||||
self.partner, self.partner.message_follower_ids.mapped("partner_id")
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user