From fe19d4c8192451ac945bc4035efa512f3bff1506 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Fri, 22 Sep 2017 15:33:09 +0200 Subject: [PATCH] [MIG] mail_footer_notified_partner: Migration to 10.0 --- .../README.rst | 30 ++++----- .../__init__.py | 0 mail_footer_notified_partner/__manifest__.py | 19 ++++++ .../i18n/de.po | 0 .../i18n/el_GR.po | 0 .../i18n/es.po | 0 .../i18n/fi.po | 0 .../i18n/fr.po | 0 .../i18n/it.po | 0 .../i18n/sl.po | 0 .../models/__init__.py | 0 .../models/mail_followers.py | 25 ++++++++ .../tests/__init__.py | 0 .../tests/test_mail_notification.py | 31 +++++++++ mail_footer_notified_partners/__openerp__.py | 18 ------ .../models/mail_followers.py | 63 ------------------- .../tests/test_mail_notification.py | 45 ------------- 17 files changed, 88 insertions(+), 143 deletions(-) rename {mail_footer_notified_partners => mail_footer_notified_partner}/README.rst (52%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/__init__.py (100%) create mode 100644 mail_footer_notified_partner/__manifest__.py rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/de.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/el_GR.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/es.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/fi.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/fr.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/it.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/i18n/sl.po (100%) rename {mail_footer_notified_partners => mail_footer_notified_partner}/models/__init__.py (100%) create mode 100644 mail_footer_notified_partner/models/mail_followers.py rename {mail_footer_notified_partners => mail_footer_notified_partner}/tests/__init__.py (100%) create mode 100644 mail_footer_notified_partner/tests/test_mail_notification.py delete mode 100644 mail_footer_notified_partners/__openerp__.py delete mode 100644 mail_footer_notified_partners/models/mail_followers.py delete mode 100644 mail_footer_notified_partners/tests/test_mail_notification.py diff --git a/mail_footer_notified_partners/README.rst b/mail_footer_notified_partner/README.rst similarity index 52% rename from mail_footer_notified_partners/README.rst rename to mail_footer_notified_partner/README.rst index ffebe8cb38..1a0022f533 100644 --- a/mail_footer_notified_partners/README.rst +++ b/mail_footer_notified_partner/README.rst @@ -1,38 +1,29 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 ================================ 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) +The partner will be added if its 'notify_email' is not 'none'. +(In order to be consistent with Odoo) Usage ===== .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :target: https://runbot.odoo-community.org/runbot/205/10.0 :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 +`_. 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 -`_. +help us smash it by providing detailed and welcomed feedback. Credits ======= @@ -41,6 +32,9 @@ Contributors ------------ * Jonathan Nemry +* Simone Rubino + +Do not contact contributors directly about support or help with technical issues. Maintainer ---------- @@ -51,6 +45,8 @@ Maintainer 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. +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_partner/__init__.py similarity index 100% rename from mail_footer_notified_partners/__init__.py rename to mail_footer_notified_partner/__init__.py diff --git a/mail_footer_notified_partner/__manifest__.py b/mail_footer_notified_partner/__manifest__.py new file mode 100644 index 0000000000..ec17adebbf --- /dev/null +++ b/mail_footer_notified_partner/__manifest__.py @@ -0,0 +1,19 @@ +# -*- 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)", + "installable": True, + "website": "http://acsone.eu", + "category": "Mail", + "version": "10.0.1.0.0", + "license": "AGPL-3", + "depends": [ + "mail", + ], +} diff --git a/mail_footer_notified_partners/i18n/de.po b/mail_footer_notified_partner/i18n/de.po similarity index 100% rename from mail_footer_notified_partners/i18n/de.po rename to mail_footer_notified_partner/i18n/de.po diff --git a/mail_footer_notified_partners/i18n/el_GR.po b/mail_footer_notified_partner/i18n/el_GR.po similarity index 100% rename from mail_footer_notified_partners/i18n/el_GR.po rename to mail_footer_notified_partner/i18n/el_GR.po diff --git a/mail_footer_notified_partners/i18n/es.po b/mail_footer_notified_partner/i18n/es.po similarity index 100% rename from mail_footer_notified_partners/i18n/es.po rename to mail_footer_notified_partner/i18n/es.po diff --git a/mail_footer_notified_partners/i18n/fi.po b/mail_footer_notified_partner/i18n/fi.po similarity index 100% rename from mail_footer_notified_partners/i18n/fi.po rename to mail_footer_notified_partner/i18n/fi.po diff --git a/mail_footer_notified_partners/i18n/fr.po b/mail_footer_notified_partner/i18n/fr.po similarity index 100% rename from mail_footer_notified_partners/i18n/fr.po rename to mail_footer_notified_partner/i18n/fr.po diff --git a/mail_footer_notified_partners/i18n/it.po b/mail_footer_notified_partner/i18n/it.po similarity index 100% rename from mail_footer_notified_partners/i18n/it.po rename to mail_footer_notified_partner/i18n/it.po diff --git a/mail_footer_notified_partners/i18n/sl.po b/mail_footer_notified_partner/i18n/sl.po similarity index 100% rename from mail_footer_notified_partners/i18n/sl.po rename to mail_footer_notified_partner/i18n/sl.po diff --git a/mail_footer_notified_partners/models/__init__.py b/mail_footer_notified_partner/models/__init__.py similarity index 100% rename from mail_footer_notified_partners/models/__init__.py rename to mail_footer_notified_partner/models/__init__.py diff --git a/mail_footer_notified_partner/models/mail_followers.py b/mail_footer_notified_partner/models/mail_followers.py new file mode 100644 index 0000000000..fa17bfab26 --- /dev/null +++ b/mail_footer_notified_partner/models/mail_followers.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, api +from odoo.tools.translate import _ + + +class MailNotification(models.Model): + _inherit = 'res.partner' + + @api.model + def _notify_send(self, body, subject, recipients, **mail_values): + body += self.get_additional_footer(recipients) + return super(MailNotification, self)._notify_send(body, subject, recipients, **mail_values) + + @api.model + def get_additional_footer(self, recipients): + recipients_name = [ + recipient.name for recipient in recipients + ] + additional_footer = u'
%s%s.
' % \ + (_('Also notified: '), + ', '.join(recipients_name)) + return additional_footer diff --git a/mail_footer_notified_partners/tests/__init__.py b/mail_footer_notified_partner/tests/__init__.py similarity index 100% rename from mail_footer_notified_partners/tests/__init__.py rename to mail_footer_notified_partner/tests/__init__.py diff --git a/mail_footer_notified_partner/tests/test_mail_notification.py b/mail_footer_notified_partner/tests/test_mail_notification.py new file mode 100644 index 0000000000..2770d48b86 --- /dev/null +++ b/mail_footer_notified_partner/tests/test_mail_notification.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import odoo.tests.common as common + + +class TestMailNotification(common.TransactionCase): + + def setUp(self): + super(TestMailNotification, self).setUp() + + 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@example.com', + } + partner1 = self.partner_obj.create(vals) + + body = 'this is the body' + subject = 'this is the subject' + recipients = partner1 + emails, recipients_nbr = self.partner_obj._notify_send(body, subject, recipients) + + self.assertFalse( + partner1.name in emails.body_html, + 'Partner name is not in the body of the mail') diff --git a/mail_footer_notified_partners/__openerp__.py b/mail_footer_notified_partners/__openerp__.py deleted file mode 100644 index 74c7cb409b..0000000000 --- a/mail_footer_notified_partners/__openerp__.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- 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/mail_followers.py b/mail_footer_notified_partners/models/mail_followers.py deleted file mode 100644 index 155b6921cc..0000000000 --- a/mail_footer_notified_partners/models/mail_followers.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- 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.model - def _notify( - self, message_id, 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.with_context(ctx))._notify( - message_id, - partners_to_notify=partners_to_notify, - force_send=force_send, user_signature=user_signature) diff --git a/mail_footer_notified_partners/tests/test_mail_notification.py b/mail_footer_notified_partners/tests/test_mail_notification.py deleted file mode 100644 index 5386ab47d0..0000000000 --- a/mail_footer_notified_partners/tests/test_mail_notification.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -import openerp.tests.common as common - - -class TestMailNotification(common.TransactionCase): - - 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')