diff --git a/mail_optional_follower_notification/README.rst b/mail_optional_follower_notification/README.rst new file mode 100644 index 000000000..93bacf136 --- /dev/null +++ b/mail_optional_follower_notification/README.rst @@ -0,0 +1,91 @@ +=================================== +Mail optional follower notification +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/12.0/mail_optional_follower_notification + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_optional_follower_notification + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +**Table of contents** + +.. contents:: + :local: + +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:: https://raw.githubusercontent.com/OCA/social/12.0/mail_optional_follower_notification/static/description/optional_follower_001.png + :alt: Default checkbox + +.. figure:: https://raw.githubusercontent.com/OCA/social/12.0/mail_optional_follower_notification/static/description/optional_follower_002.png + :alt: Checkbox to avoid to notify automatically followers + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Adrien Peiffer +* Laurent Mignon +* Andrea Stirpe + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_optional_follower_notification/__init__.py b/mail_optional_follower_notification/__init__.py new file mode 100644 index 000000000..93aa2c1f8 --- /dev/null +++ b/mail_optional_follower_notification/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models +from . import wizard diff --git a/mail_optional_follower_notification/__manifest__.py b/mail_optional_follower_notification/__manifest__.py new file mode 100644 index 000000000..d0b549639 --- /dev/null +++ b/mail_optional_follower_notification/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Mail optional follower notification", + "summary": "Choose to notify followers on mail.compose.message", + "author": "ACSONE SA/NV," + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "category": "Social Network", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "depends": [ + "mail", + ], + "data": [ + "wizard/mail_compose_message_view.xml", + ], +} diff --git a/mail_optional_follower_notification/i18n/am.po b/mail_optional_follower_notification/i18n/am.po new file mode 100644 index 000000000..65c4e856e --- /dev/null +++ b/mail_optional_follower_notification/i18n/am.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_optional_follower_notification +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-17 01:02+0000\n" +"PO-Revision-Date: 2017-05-17 01:02+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Amharic (https://www.transifex.com/oca/teams/23907/am/)\n" +"Language: am\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: mail_optional_follower_notification +#: model:ir.ui.view,arch_db:mail_optional_follower_notification.email_compose_message_wizard_inherit_form +msgid "" +") +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models, api + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.model + def _notify(self, message, rdata, record, force_send=False, + send_after_commit=True, model_description=False, + mail_auto_delete=True): + if self.env.context.get('force_partners_to_notify'): + partners_to_notify =\ + self.env.context.get('force_partners_to_notify') + record = self.filtered(lambda p: p.id in partners_to_notify) + return super()._notify( + message, rdata, record, + force_send=force_send, send_after_commit=send_after_commit, + model_description=model_description, + mail_auto_delete=mail_auto_delete) diff --git a/mail_optional_follower_notification/readme/CONTRIBUTORS.rst b/mail_optional_follower_notification/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..bea4300dc --- /dev/null +++ b/mail_optional_follower_notification/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Adrien Peiffer +* Laurent Mignon +* Andrea Stirpe diff --git a/mail_optional_follower_notification/readme/DESCRIPTION.rst b/mail_optional_follower_notification/readme/DESCRIPTION.rst new file mode 100644 index 000000000..04bb275cd --- /dev/null +++ b/mail_optional_follower_notification/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +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. diff --git a/mail_optional_follower_notification/readme/USAGE.rst b/mail_optional_follower_notification/readme/USAGE.rst new file mode 100644 index 000000000..bf0bbb3db --- /dev/null +++ b/mail_optional_follower_notification/readme/USAGE.rst @@ -0,0 +1,10 @@ +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 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 000000000..3a0328b51 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 000000000..897e596cf 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 000000000..24d9d9756 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 000000000..17a2936a2 --- /dev/null +++ b/mail_optional_follower_notification/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +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 000000000..724116a60 --- /dev/null +++ b/mail_optional_follower_notification/tests/test_mail_optional_follower_notifications.py @@ -0,0 +1,57 @@ +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import common + + +class TestMailOptionalFollowernotifications(common.TransactionCase): + + def setUp(self): + super().setUp() + self.partner_obj = self.env['res.partner'] + self.partner_01 = self.env.ref('base.res_partner_2') + self.demo_user = self.env.ref('base.user_demo') + self.partner_03 = self.demo_user.copy().partner_id + + 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'] + self.partner_01.message_subscribe( + partner_ids=[self.demo_user.partner_id.id]) + values = mail_compose.with_context(ctx)\ + .onchange_template_id(False, 'comment', 'res.partner', + self.partner_01.id)['value'] + values['partner_ids'] = [(4, self.demo_user.partner_id.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.notification_ids.mapped('res_partner_id').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.notification_ids.mapped('res_partner_id').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 000000000..2d9c29a8b --- /dev/null +++ b/mail_optional_follower_notification/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +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 000000000..25efe0df2 --- /dev/null +++ b/mail_optional_follower_notification/wizard/mail_compose_message.py @@ -0,0 +1,20 @@ +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models, fields, api + + +class MailComposeMessage(models.TransientModel): + _inherit = 'mail.compose.message' + + notify_followers = fields.Boolean(default=True) + + @api.multi + def send_mail(self, auto_commit=False): + ctx = self.env.context.copy() + for wizard in self: + ctx['notify_followers'] = wizard.notify_followers + wizard = wizard.with_context(ctx) + super(MailComposeMessage, wizard).send_mail( + auto_commit=auto_commit) + 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 000000000..b252a0ecb --- /dev/null +++ b/mail_optional_follower_notification/wizard/mail_compose_message_view.xml @@ -0,0 +1,17 @@ + + + + + mail.compose.message + + + + + + + - Warning : Followers will not be notified but they can access the notification directly from the document (if they are allowed to) + + + + +