From 38dbb7f412d01ddd29a963c7ea47f75896433a4b Mon Sep 17 00:00:00 2001 From: "Jonathan Nemry (ACSONE)" Date: Wed, 20 Jan 2016 16:03:19 +0100 Subject: [PATCH] [NEW][mail_footer_notified_partners] This module adds into the footer the partner's name notified by this email --- mail_footer_notified_partners/README.rst | 56 +++++++++++++++++ mail_footer_notified_partners/__init__.py | 4 ++ mail_footer_notified_partners/__openerp__.py | 18 ++++++ .../models/__init__.py | 4 ++ .../models/mail_followers.py | 63 +++++++++++++++++++ .../tests/__init__.py | 4 ++ .../tests/test_mail_notification.py | 45 +++++++++++++ 7 files changed, 194 insertions(+) create mode 100644 mail_footer_notified_partners/README.rst create mode 100644 mail_footer_notified_partners/__init__.py create mode 100644 mail_footer_notified_partners/__openerp__.py create mode 100644 mail_footer_notified_partners/models/__init__.py create mode 100644 mail_footer_notified_partners/models/mail_followers.py create mode 100644 mail_footer_notified_partners/tests/__init__.py create mode 100644 mail_footer_notified_partners/tests/test_mail_notification.py diff --git a/mail_footer_notified_partners/README.rst b/mail_footer_notified_partners/README.rst new file mode 100644 index 00000000..ffebe8cb --- /dev/null +++ b/mail_footer_notified_partners/README.rst @@ -0,0 +1,56 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +================================ +Notified partners in mail footer +================================ + +This module adds the list of notified partners in the footer of notification e-mails sent by Odoo. +The partner will be added if its 'notify_email' is not 'none' or if the partner is linked to a user. +(In order to be consitency with Odoo) + +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/8.0 + +Known issues / Roadmap +====================== + +* Add a second boolean into the partner form in order to manage the added +partners with an other field than 'notify_email' + +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 +`_. + +Credits +======= + +Contributors +------------ + +* Jonathan Nemry + +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_footer_notified_partners/__init__.py b/mail_footer_notified_partners/__init__.py new file mode 100644 index 00000000..37c0ad40 --- /dev/null +++ b/mail_footer_notified_partners/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/mail_footer_notified_partners/__openerp__.py b/mail_footer_notified_partners/__openerp__.py new file mode 100644 index 00000000..74c7cb40 --- /dev/null +++ b/mail_footer_notified_partners/__openerp__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': "Notified partners in mail footer", + 'summary': """ + This module adds the list of notified partners in the footer of + notification e-mails sent by Odoo. + """, + 'author': "ACSONE SA/NV,Odoo Community Association (OCA)", + 'website': "http://acsone.eu", + 'category': 'Mail', + 'version': '8.0.1.0.0', + 'license': 'AGPL-3', + 'depends': [ + 'mail', + ], +} diff --git a/mail_footer_notified_partners/models/__init__.py b/mail_footer_notified_partners/models/__init__.py new file mode 100644 index 00000000..de1bfecf --- /dev/null +++ b/mail_footer_notified_partners/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import mail_followers diff --git a/mail_footer_notified_partners/models/mail_followers.py b/mail_footer_notified_partners/models/mail_followers.py new file mode 100644 index 00000000..1d32d2cd --- /dev/null +++ b/mail_footer_notified_partners/models/mail_followers.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, api +from openerp import tools +from openerp.tools.translate import _ + + +class MailNotification(models.Model): + + _inherit = 'mail.notification' + + @api.model + def _get_partner_names(self, partner_ids): + """ + :type partner_ids: [integer] + :param partner_ids: ids of the partner followers + :rparam: list of the partner'name that are also a user or having + notify_email attribute not none + """ + partners = self.env['res.partner'].browse(partner_ids) + partners_name = [ + partner.name for partner in partners if + partner.user_ids or partner.notify_email != 'none' + ] + return partners_name + + @api.model + def get_signature_footer( + self, user_id, res_model=None, res_id=None, user_signature=True): + """ + Override this method to add name of notified partners into the mail + footer + """ + footer = super(MailNotification, self).get_signature_footer( + user_id, res_model=res_model, res_id=res_id, + user_signature=user_signature) + partner_ids = self.env.context.get('partners_to_notify') + if footer and partner_ids: + partners_name = self._get_partner_names(partner_ids) + additional_footer = u'
%s%s.
' %\ + (_('Also notified: '), + ', '.join(partners_name)) + footer = tools.append_content_to_html( + additional_footer, footer, plaintext=False, + container_tag='div') + + return footer + + @api.one + def _notify( + self, partners_to_notify=None, force_send=False, + user_signature=True): + ctx = self.env.context.copy() + if not self.env.context.get('mail_notify_noemail'): + ctx.update({ + 'partners_to_notify': partners_to_notify, + }) + return super(MailNotification, self._model)._notify( + self.env.cr, self.env.uid, self.id, + partners_to_notify=partners_to_notify, + force_send=force_send, user_signature=user_signature, context=ctx) diff --git a/mail_footer_notified_partners/tests/__init__.py b/mail_footer_notified_partners/tests/__init__.py new file mode 100644 index 00000000..4488e7cd --- /dev/null +++ b/mail_footer_notified_partners/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_mail_notification diff --git a/mail_footer_notified_partners/tests/test_mail_notification.py b/mail_footer_notified_partners/tests/test_mail_notification.py new file mode 100644 index 00000000..c8c5442e --- /dev/null +++ b/mail_footer_notified_partners/tests/test_mail_notification.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from anybox.testing.openerp import SharedSetupTransactionCase + + +class TestMailNotification(SharedSetupTransactionCase): + + def setUp(self): + super(TestMailNotification, self).setUp() + + self.mail_notification_obj = self.env['mail.notification'] + self.partner_obj = self.env['res.partner'] + + self.registry('ir.model').clear_caches() + self.registry('ir.model.data').clear_caches() + + def test_get_signature_footer(self): + + vals = { + 'name': 'p1@exemple.com', + 'notify_email': 'none', + } + partner1 = self.partner_obj.create(vals) + vals = { + 'name': 'p2@exemple.com', + 'notify_email': 'always', + } + partner2 = self.partner_obj.create(vals) + footer = self.mail_notification_obj.get_signature_footer(self.env.uid) + self.assertFalse( + partner1.name in footer or partner2.name in footer, + 'Standard behavior does not add notified partners into the footer') + + footer = self.mail_notification_obj.with_context( + partners_to_notify=[partner1.id, partner2.id] + ).get_signature_footer(self.env.uid) + + self.assertFalse( + partner1.name in footer, + 'Partner with "notify_email: "none" should not be into the footer') + self.assertTrue( + partner2.name in footer, + 'Partner with "notify_email: "always" should be into the footer')