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