mirror of https://github.com/OCA/social.git
Merge pull request #37 from acsone/mail_footer_notified_partners
[NEW][mail_footer_notified_partners]pull/39/head
commit
3a14bbcd47
|
@ -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
|
||||
<https://github.com/OCA/205/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
|
||||
<https://github.com/OCA/
|
||||
205/issues/new?body=module:%20
|
||||
mail_footer_notified_partners%0Aversion:%20
|
||||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Jonathan Nemry <jonathan.nemry@acsone.eu>
|
||||
|
||||
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.
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 ACSONE SA/NV <https://acsone.eu>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import models
|
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 ACSONE SA/NV <https://acsone.eu>
|
||||
# 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',
|
||||
],
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 ACSONE SA/NV <https://acsone.eu>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import mail_followers
|
|
@ -0,0 +1,63 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 ACSONE SA/NV <https://acsone.eu>
|
||||
# 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'<br /><small>%s%s.</small><br />' %\
|
||||
(_('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)
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 ACSONE SA/NV <https://acsone.eu>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import test_mail_notification
|
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 ACSONE SA/NV <https://acsone.eu>
|
||||
# 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')
|
Loading…
Reference in New Issue