[IMP] disable the option to create followers that do not meet the conditions

This commit is contained in:
Enric Tobella 2018-04-04 10:19:13 +02:00 committed by Aungkokolin1997
parent 840deb6218
commit 28ceac3986
12 changed files with 148 additions and 20 deletions

View File

@ -7,6 +7,8 @@ Restrict follower selection
This module was written to allow you to restrict the selection of possible followers. For example, if you use the social ERP functions only internally, it makes sense to filter possible followers for being employees. Otherwise, you'll get a quite crowded list of partners to choose from. This module was written to allow you to restrict the selection of possible followers. For example, if you use the social ERP functions only internally, it makes sense to filter possible followers for being employees. Otherwise, you'll get a quite crowded list of partners to choose from.
Moreover, the module disables the option to automatically add followers that do not meet the domain.
Configuration Configuration
============= =============
@ -21,7 +23,7 @@ Usage
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0 :target: https://runbot.odoo-community.org/runbot/205/11.0
For further information, please visit: For further information, please visit:
@ -43,6 +45,7 @@ Contributors
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Nguyen Tan Phuc <phuc.nt@komit-consulting.com> * Nguyen Tan Phuc <phuc.nt@komit-consulting.com>
* Enric Tobella <etobella@creublanca.es>
Maintainer Maintainer
---------- ----------

View File

@ -4,8 +4,8 @@
{ {
"name": "Restrict follower selection", "name": "Restrict follower selection",
"version": "11.0.1.0.0", "version": "11.0.2.0.0",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Creu Blanca,Odoo Community Association (OCA)",
"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",

View File

@ -10,11 +10,12 @@ msgstr ""
"POT-Creation-Date: 2015-09-30 16:56+0000\n" "POT-Creation-Date: 2015-09-30 16:56+0000\n"
"PO-Revision-Date: 2015-09-30 16:56+0000\n" "PO-Revision-Date: 2015-09-30 16:56+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>\n" "Last-Translator: OCA Transbot <transbot@odoo-community.org>\n"
"Language-Team: English (http://www.transifex.com/oca/OCA-social-8-0/language/en/)\n" "Language-Team: English (http://www.transifex.com/oca/OCA-social-8-0/language/"
"en/)\n"
"Language: en\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
@ -22,6 +23,11 @@ msgstr ""
msgid "Configure the restriction on followers" msgid "Configure the restriction on followers"
msgstr "Configure the restriction on followers" msgstr "Configure the restriction on followers"
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_followers
msgid "Document Followers"
msgstr ""
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite
msgid "Invite wizard" msgid "Invite wizard"

View File

@ -12,10 +12,10 @@ msgstr ""
"PO-Revision-Date: 2017-07-22 09:45+0000\n" "PO-Revision-Date: 2017-07-22 09:45+0000\n"
"Last-Translator: Quentin THEURET <odoo@kerpeo.com>, 2017\n" "Last-Translator: Quentin THEURET <odoo@kerpeo.com>, 2017\n"
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" "Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
"Language: fr\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
@ -23,6 +23,11 @@ msgstr ""
msgid "Configure the restriction on followers" msgid "Configure the restriction on followers"
msgstr "Configurer les restrictions sur les abonnés" msgstr "Configurer les restrictions sur les abonnés"
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_followers
msgid "Document Followers"
msgstr ""
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite
msgid "Invite wizard" msgid "Invite wizard"

View File

@ -12,17 +12,23 @@ msgstr ""
"PO-Revision-Date: 2016-11-29 14:24+0000\n" "PO-Revision-Date: 2016-11-29 14:24+0000\n"
"Last-Translator: Bole <bole@dajmi5.com>, 2016\n" "Last-Translator: Bole <bole@dajmi5.com>, 2016\n"
"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" "Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n"
"Language: hr\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: hr\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.actions.act_window,name:mail_restrict_follower_selection.action_setup #: model:ir.actions.act_window,name:mail_restrict_follower_selection.action_setup
msgid "Configure the restriction on followers" msgid "Configure the restriction on followers"
msgstr "Postavi ograničenja na pratitelje" msgstr "Postavi ograničenja na pratitelje"
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_followers
msgid "Document Followers"
msgstr ""
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite
msgid "Invite wizard" msgid "Invite wizard"

View File

@ -12,10 +12,10 @@ msgstr ""
"PO-Revision-Date: 2017-05-17 01:02+0000\n" "PO-Revision-Date: 2017-05-17 01:02+0000\n"
"Last-Translator: Marius Marolla <mariusmarolla@gmail.com>, 2017\n" "Last-Translator: Marius Marolla <mariusmarolla@gmail.com>, 2017\n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" "Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"Language: it\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: it\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
@ -23,6 +23,11 @@ msgstr ""
msgid "Configure the restriction on followers" msgid "Configure the restriction on followers"
msgstr "Imposta restrizioni sui follower" msgstr "Imposta restrizioni sui follower"
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_followers
msgid "Document Followers"
msgstr ""
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite
msgid "Invite wizard" msgid "Invite wizard"

View File

@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_restrict_follower_selection
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: mail_restrict_follower_selection
#: model:ir.actions.act_window,name:mail_restrict_follower_selection.action_setup
msgid "Configure the restriction on followers"
msgstr ""
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_followers
msgid "Document Followers"
msgstr ""
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite
msgid "Invite wizard"
msgstr ""

View File

@ -11,18 +11,25 @@ msgstr ""
"POT-Creation-Date: 2015-09-30 16:56+0000\n" "POT-Creation-Date: 2015-09-30 16:56+0000\n"
"PO-Revision-Date: 2015-10-01 13:00+0000\n" "PO-Revision-Date: 2015-10-01 13:00+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>\n" "Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>\n"
"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-social-8-0/language/sl/)\n" "Language-Team: Slovenian (http://www.transifex.com/oca/OCA-social-8-0/"
"language/sl/)\n"
"Language: sl\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: sl\n" "Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" "%100==4 ? 2 : 3);\n"
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.actions.act_window,name:mail_restrict_follower_selection.action_setup #: model:ir.actions.act_window,name:mail_restrict_follower_selection.action_setup
msgid "Configure the restriction on followers" msgid "Configure the restriction on followers"
msgstr "Nastavitev omejitev za sledilce" msgstr "Nastavitev omejitev za sledilce"
#. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_followers
msgid "Document Followers"
msgstr ""
#. module: mail_restrict_follower_selection #. module: mail_restrict_follower_selection
#: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite
msgid "Invite wizard" msgid "Invite wizard"

View File

@ -2,4 +2,5 @@
# Copyright (C) 2017 Komit <http://www.komit-consulting.com> # Copyright (C) 2017 Komit <http://www.komit-consulting.com>
# 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 . import mail_followers
from . import mail_wizard_invite from . import mail_wizard_invite

View File

@ -0,0 +1,24 @@
# Copyright (C) 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models
from odoo.tools.safe_eval import safe_eval
class MailFollowers(models.Model):
_inherit = 'mail.followers'
@api.model
def _add_follower_command(self, res_model, res_ids, partner_data,
channel_data, force=True):
domain = self.env[
'mail.wizard.invite'
]._mail_restrict_follower_selection_get_domain()
partners = self.env['res.partner'].search(
[('id', 'in', list(partner_data))] +
safe_eval(domain)
)
return super()._add_follower_command(
res_model, res_ids,
{p.id: partner_data[p.id] for p in partners},
channel_data, force=force)

View File

@ -12,10 +12,10 @@ class MailWizardInvite(models.TransientModel):
@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'].get_param( return self.env['ir.config_parameter'].sudo().get_param(
"{0}.{1}".format(parameter_name, "{0}.{1}".format(parameter_name,
self.env.context.get('default_res_model')), self.env.context.get('default_res_model')),
self.env['ir.config_parameter'].get_param( self.env['ir.config_parameter'].sudo().get_param(
parameter_name, default='[]') parameter_name, default='[]')
) )

View File

@ -3,14 +3,55 @@
# 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 openerp.tests.common import TransactionCase from odoo.tests.common import TransactionCase
class TestMailRestrictFollowerSelection(TransactionCase): class TestMailRestrictFollowerSelection(TransactionCase):
def setUp(self):
super().setUp()
self.partner = self.env['res.partner'].create({
'name': 'Partner',
'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):
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.send_mail_action()
def test_followers_meet(self):
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')
)
def test_followers_not_meet(self):
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')
)