diff --git a/mail_restrict_follower_selection/README.rst b/mail_restrict_follower_selection/README.rst index bbcd1ae..fb0656d 100644 --- a/mail_restrict_follower_selection/README.rst +++ b/mail_restrict_follower_selection/README.rst @@ -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. +Moreover, the module disables the option to automatically add followers that do not meet the domain. + Configuration ============= @@ -21,7 +23,7 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :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: @@ -43,6 +45,7 @@ Contributors * Holger Brunn * Nguyen Tan Phuc +* Enric Tobella Maintainer ---------- diff --git a/mail_restrict_follower_selection/__manifest__.py b/mail_restrict_follower_selection/__manifest__.py index 2f81a54..bfeb8bf 100644 --- a/mail_restrict_follower_selection/__manifest__.py +++ b/mail_restrict_follower_selection/__manifest__.py @@ -4,8 +4,8 @@ { "name": "Restrict follower selection", - "version": "11.0.1.0.0", - "author": "Therp BV,Odoo Community Association (OCA)", + "version": "11.0.2.0.0", + "author": "Therp BV,Creu Blanca,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Social Network", "summary": "Define a domain from which followers can be selected", diff --git a/mail_restrict_follower_selection/i18n/en.po b/mail_restrict_follower_selection/i18n/en.po index 1d50b01..b6c0235 100644 --- a/mail_restrict_follower_selection/i18n/en.po +++ b/mail_restrict_follower_selection/i18n/en.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * mail_restrict_follower_selection -# +# # Translators: msgid "" msgstr "" @@ -10,11 +10,12 @@ msgstr "" "POT-Creation-Date: 2015-09-30 16:56+0000\n" "PO-Revision-Date: 2015-09-30 16:56+0000\n" "Last-Translator: OCA Transbot \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" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: en\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: mail_restrict_follower_selection @@ -22,6 +23,11 @@ msgstr "" msgid "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 #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite msgid "Invite wizard" diff --git a/mail_restrict_follower_selection/i18n/fr.po b/mail_restrict_follower_selection/i18n/fr.po index 496e862..4a89521 100644 --- a/mail_restrict_follower_selection/i18n/fr.po +++ b/mail_restrict_follower_selection/i18n/fr.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * mail_restrict_follower_selection -# +# # Translators: # Quentin THEURET , 2017 msgid "" @@ -12,10 +12,10 @@ msgstr "" "PO-Revision-Date: 2017-07-22 09:45+0000\n" "Last-Translator: Quentin THEURET , 2017\n" "Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: fr\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #. module: mail_restrict_follower_selection @@ -23,6 +23,11 @@ msgstr "" msgid "Configure the restriction on followers" 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 #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite msgid "Invite wizard" diff --git a/mail_restrict_follower_selection/i18n/hr.po b/mail_restrict_follower_selection/i18n/hr.po index 2986af1..4d7bc08 100644 --- a/mail_restrict_follower_selection/i18n/hr.po +++ b/mail_restrict_follower_selection/i18n/hr.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * mail_restrict_follower_selection -# +# # Translators: # Bole , 2016 msgid "" @@ -12,17 +12,23 @@ msgstr "" "PO-Revision-Date: 2016-11-29 14:24+0000\n" "Last-Translator: Bole , 2016\n" "Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: hr\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" +"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" #. module: mail_restrict_follower_selection #: model:ir.actions.act_window,name:mail_restrict_follower_selection.action_setup msgid "Configure the restriction on followers" 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 #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite msgid "Invite wizard" diff --git a/mail_restrict_follower_selection/i18n/it.po b/mail_restrict_follower_selection/i18n/it.po index b3df718..10a71b6 100644 --- a/mail_restrict_follower_selection/i18n/it.po +++ b/mail_restrict_follower_selection/i18n/it.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * mail_restrict_follower_selection -# +# # Translators: # Marius Marolla , 2017 msgid "" @@ -12,10 +12,10 @@ msgstr "" "PO-Revision-Date: 2017-05-17 01:02+0000\n" "Last-Translator: Marius Marolla , 2017\n" "Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Language: it\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: mail_restrict_follower_selection @@ -23,6 +23,11 @@ msgstr "" msgid "Configure the restriction on followers" 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 #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite msgid "Invite wizard" diff --git a/mail_restrict_follower_selection/i18n/mail_restrict_follower_selection.pot b/mail_restrict_follower_selection/i18n/mail_restrict_follower_selection.pot new file mode 100644 index 0000000..6bcf2f7 --- /dev/null +++ b/mail_restrict_follower_selection/i18n/mail_restrict_follower_selection.pot @@ -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 "" + diff --git a/mail_restrict_follower_selection/i18n/sl.po b/mail_restrict_follower_selection/i18n/sl.po index 370eb81..d64d0ba 100644 --- a/mail_restrict_follower_selection/i18n/sl.po +++ b/mail_restrict_follower_selection/i18n/sl.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * mail_restrict_follower_selection -# +# # Translators: # Matjaž Mozetič , 2015 msgid "" @@ -11,18 +11,25 @@ msgstr "" "POT-Creation-Date: 2015-09-30 16:56+0000\n" "PO-Revision-Date: 2015-10-01 13:00+0000\n" "Last-Translator: Matjaž Mozetič \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" "Content-Type: text/plain; charset=UTF-8\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%100==4 ? 2 : 3);\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" +"%100==4 ? 2 : 3);\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 "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 #: model:ir.model,name:mail_restrict_follower_selection.model_mail_wizard_invite msgid "Invite wizard" diff --git a/mail_restrict_follower_selection/models/__init__.py b/mail_restrict_follower_selection/models/__init__.py index 422ffaf..a757c6b 100644 --- a/mail_restrict_follower_selection/models/__init__.py +++ b/mail_restrict_follower_selection/models/__init__.py @@ -2,4 +2,5 @@ # Copyright (C) 2017 Komit # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import mail_followers from . import mail_wizard_invite diff --git a/mail_restrict_follower_selection/models/mail_followers.py b/mail_restrict_follower_selection/models/mail_followers.py new file mode 100644 index 0000000..15e906e --- /dev/null +++ b/mail_restrict_follower_selection/models/mail_followers.py @@ -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) diff --git a/mail_restrict_follower_selection/models/mail_wizard_invite.py b/mail_restrict_follower_selection/models/mail_wizard_invite.py index 216e26b..1d8b31c 100644 --- a/mail_restrict_follower_selection/models/mail_wizard_invite.py +++ b/mail_restrict_follower_selection/models/mail_wizard_invite.py @@ -12,10 +12,10 @@ class MailWizardInvite(models.TransientModel): @api.model def _mail_restrict_follower_selection_get_domain(self): 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, 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='[]') ) diff --git a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py index d1905b1..4bf6410 100644 --- a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py +++ b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py @@ -3,14 +3,55 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from lxml import etree -from openerp.tests.common import TransactionCase +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', + }) + 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')) + + 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') + )