diff --git a/mail_optional_follower_notification/README.rst b/mail_optional_follower_notification/README.rst new file mode 100644 index 00000000..3132e6f0 --- /dev/null +++ b/mail_optional_follower_notification/README.rst @@ -0,0 +1,60 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +==================================== +Mail optional follower notifications +==================================== + +This module adds the possibility to choose if you want to automatically +notify followers on mail.compose.message. By default, Odoo notify +automatically all followers. + +Usage +===== + +To use this module, you need to use the checkbox near "Followers of the document and" on mail.compose.message: + +This field it's initialized to true to keep the standard behavior. + +.. figure:: static/description/optional_follower_001.png + :alt: Default checkbox + +.. figure:: static/description/optional_follower_002.png + :alt: Checkbox to avoid to notify automatically followers + +.. 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/8.0 + + * https://www.odoo.com/forum/help-1 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Adrien Peiffer + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. \ No newline at end of file diff --git a/mail_optional_follower_notification/__init__.py b/mail_optional_follower_notification/__init__.py new file mode 100644 index 00000000..98aa84d4 --- /dev/null +++ b/mail_optional_follower_notification/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models +from . import wizard diff --git a/mail_optional_follower_notification/__openerp__.py b/mail_optional_follower_notification/__openerp__.py new file mode 100644 index 00000000..5421f288 --- /dev/null +++ b/mail_optional_follower_notification/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "Mail optional follower notification", + + 'summary': """ + Choose if you want to automatically notify followers + on mail.compose.message""", + 'author': 'ACSONE SA/NV,' + 'Odoo Community Association (OCA)', + 'website': "http://acsone.eu", + 'category': 'Social Network', + 'version': '8.0.1.0.0', + 'license': 'AGPL-3', + 'depends': [ + 'mail', + ], + 'data': [ + 'wizard/mail_compose_message_view.xml', + ], +} diff --git a/mail_optional_follower_notification/models/__init__.py b/mail_optional_follower_notification/models/__init__.py new file mode 100644 index 00000000..cc213b9f --- /dev/null +++ b/mail_optional_follower_notification/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import mail_message +from . import mail_notification diff --git a/mail_optional_follower_notification/models/mail_message.py b/mail_optional_follower_notification/models/mail_message.py new file mode 100644 index 00000000..fe64abc0 --- /dev/null +++ b/mail_optional_follower_notification/models/mail_message.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api + + +class MailMessage(models.Model): + _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'): + partner_list = self.resolve_2many_commands( + 'partner_ids', values.get('partner_ids'), fields=['id']) + force_partners_to_notify = [d['id'] for d in partner_list] + ctx['force_partners_to_notify'] = force_partners_to_notify + return super(MailMessage, self.with_context(ctx)).create(values) diff --git a/mail_optional_follower_notification/models/mail_notification.py b/mail_optional_follower_notification/models/mail_notification.py new file mode 100644 index 00000000..47cf08b6 --- /dev/null +++ b/mail_optional_follower_notification/models/mail_notification.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api + + +class MailNotification(models.Model): + _inherit = 'mail.notification' + + @api.model + def _notify(self, message_id, partners_to_notify=None, + force_send=False, user_signature=True): + if self.env.context.get('force_partners_to_notify'): + partners_to_notify =\ + self.env.context.get('force_partners_to_notify') + super(MailNotification, self)._notify( + message_id, partners_to_notify=partners_to_notify, + force_send=force_send, user_signature=user_signature) diff --git a/mail_optional_follower_notification/static/description/icon.png b/mail_optional_follower_notification/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mail_optional_follower_notification/static/description/icon.png differ diff --git a/mail_optional_follower_notification/static/description/optional_follower_001.png b/mail_optional_follower_notification/static/description/optional_follower_001.png new file mode 100644 index 00000000..897e596c Binary files /dev/null and b/mail_optional_follower_notification/static/description/optional_follower_001.png differ diff --git a/mail_optional_follower_notification/static/description/optional_follower_002.png b/mail_optional_follower_notification/static/description/optional_follower_002.png new file mode 100644 index 00000000..24d9d975 Binary files /dev/null and b/mail_optional_follower_notification/static/description/optional_follower_002.png differ diff --git a/mail_optional_follower_notification/tests/__init__.py b/mail_optional_follower_notification/tests/__init__.py new file mode 100644 index 00000000..2a6791af --- /dev/null +++ b/mail_optional_follower_notification/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_mail_optional_follower_notifications diff --git a/mail_optional_follower_notification/tests/test_mail_optional_follower_notifications.py b/mail_optional_follower_notification/tests/test_mail_optional_follower_notifications.py new file mode 100644 index 00000000..4f128323 --- /dev/null +++ b/mail_optional_follower_notification/tests/test_mail_optional_follower_notifications.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common + + +class TestMailOptionalFollowernotifications(common.TransactionCase): + + def setUp(self): + super(TestMailOptionalFollowernotifications, self).setUp() + self.partner_obj = self.env['res.partner'] + self.partner_01 = self.env.ref('base.res_partner_2') + self.partner_02 = self.env.ref('base.res_partner_13') + self.partner_03 = self.env.ref('base.res_partner_5') + + 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'] + values = mail_compose.with_context(ctx)\ + .onchange_template_id(False, 'comment', 'res.partner', + self.partner_01.id)['value'] + values['partner_ids'] = [(4, self.partner_02.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)]) + self.assertEqual(len(res.ids), 1) + message = self.env['mail.message'] + for record in res: + if record.notified_partner_ids.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])] + 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'] + for record in res: + if record.notified_partner_ids.ids == [self.partner_03.id] and\ + record.partner_ids.ids == [self.partner_03.id]: + message += record + self.assertEqual(len(message.ids), 1) diff --git a/mail_optional_follower_notification/wizard/__init__.py b/mail_optional_follower_notification/wizard/__init__.py new file mode 100644 index 00000000..56c0250a --- /dev/null +++ b/mail_optional_follower_notification/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import mail_compose_message diff --git a/mail_optional_follower_notification/wizard/mail_compose_message.py b/mail_optional_follower_notification/wizard/mail_compose_message.py new file mode 100644 index 00000000..b6bc9053 --- /dev/null +++ b/mail_optional_follower_notification/wizard/mail_compose_message.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api + + +class MailComposeMessage(models.TransientModel): + _inherit = 'mail.compose.message' + + notify_followers = fields.Boolean(default=True) + + @api.multi + def send_mail(self): + for wizard in self: + wizard = wizard.with_context( + notify_followers=wizard.notify_followers) + super(MailComposeMessage, wizard).send_mail() + return {'type': 'ir.actions.act_window_close'} diff --git a/mail_optional_follower_notification/wizard/mail_compose_message_view.xml b/mail_optional_follower_notification/wizard/mail_compose_message_view.xml new file mode 100644 index 00000000..62078101 --- /dev/null +++ b/mail_optional_follower_notification/wizard/mail_compose_message_view.xml @@ -0,0 +1,18 @@ + + + + + mail.compose.message.form (mail_optional_autofollow) + mail.compose.message + + + + + + + - Warning : Followers will not be notified but they can access the notification directly from the document (if they are allowed to) + + + + + \ No newline at end of file