From 1665bc95ec47a3cf1caa0171e1daf8da18151112 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Mon, 24 Oct 2016 11:46:07 +0200 Subject: [PATCH] Migration of mail_optional_follower_notification to 10.0 --- mail_optional_follower_notification/README.rst | 5 ++--- .../{__openerp__.py => __manifest__.py} | 0 .../models/mail_message.py | 14 +++++++++++++- .../models/res_partner.py | 8 +++++--- .../test_mail_optional_follower_notifications.py | 13 +++++++------ .../wizard/mail_compose_message.py | 2 +- .../wizard/mail_compose_message_view.xml | 4 ++-- 7 files changed, 30 insertions(+), 16 deletions(-) rename mail_optional_follower_notification/{__openerp__.py => __manifest__.py} (100%) diff --git a/mail_optional_follower_notification/README.rst b/mail_optional_follower_notification/README.rst index 2e08dc16..0998cc9d 100644 --- a/mail_optional_follower_notification/README.rst +++ b/mail_optional_follower_notification/README.rst @@ -25,7 +25,7 @@ This field it's initialized to true to keep the standard behavior. .. 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/9.0 + :target: https://runbot.odoo-community.org/runbot/205/10.0 * https://www.odoo.com/forum/help-1 @@ -35,8 +35,7 @@ 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 `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback. Credits ======= diff --git a/mail_optional_follower_notification/__openerp__.py b/mail_optional_follower_notification/__manifest__.py similarity index 100% rename from mail_optional_follower_notification/__openerp__.py rename to mail_optional_follower_notification/__manifest__.py diff --git a/mail_optional_follower_notification/models/mail_message.py b/mail_optional_follower_notification/models/mail_message.py index fe64abc0..4768bb81 100644 --- a/mail_optional_follower_notification/models/mail_message.py +++ b/mail_optional_follower_notification/models/mail_message.py @@ -2,7 +2,7 @@ # Copyright 2016 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, api +from odoo import models, api class MailMessage(models.Model): @@ -17,3 +17,15 @@ class MailMessage(models.Model): 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) + + @api.multi + def _notify(self, force_send=False, send_after_commit=True, + user_signature=True): + res = super(MailMessage, self)._notify( + force_send=force_send, send_after_commit=send_after_commit, + user_signature=user_signature) + if not self.env.context.get('notify_followers'): + # Needaction only for recipients + self.needaction_partner_ids = [(6, 0, self.partner_ids.ids)] + return res + diff --git a/mail_optional_follower_notification/models/res_partner.py b/mail_optional_follower_notification/models/res_partner.py index 4c7e53f4..f32d9bb0 100644 --- a/mail_optional_follower_notification/models/res_partner.py +++ b/mail_optional_follower_notification/models/res_partner.py @@ -2,17 +2,19 @@ # Copyright 2016 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, api +from odoo import models, api class ResPartner(models.Model): _inherit = 'res.partner' @api.multi - def _notify(self, message, force_send=False, user_signature=True): + def _notify(self, message, force_send=False, send_after_commit=True, + user_signature=True): if self.env.context.get('force_partners_to_notify'): partners_to_notify =\ self.env.context.get('force_partners_to_notify') self = self.filtered(lambda p: p.id in partners_to_notify) super(ResPartner, self)._notify( - message, force_send=False, user_signature=True) + message, force_send=force_send, + send_after_commit=send_after_commit, user_signature=user_signature) 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 index 1ca61bfb..91936728 100644 --- a/mail_optional_follower_notification/tests/test_mail_optional_follower_notifications.py +++ b/mail_optional_follower_notification/tests/test_mail_optional_follower_notifications.py @@ -2,7 +2,7 @@ # Copyright 2016 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.tests import common +from odoo.tests import common class TestMailOptionalFollowernotifications(common.TransactionCase): @@ -11,8 +11,8 @@ class TestMailOptionalFollowernotifications(common.TransactionCase): 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_3') - self.partner_03 = self.env.ref('base.res_partner_4') + 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() @@ -22,10 +22,11 @@ class TestMailOptionalFollowernotifications(common.TransactionCase): 'default_composition_mode': 'comment', }) mail_compose = self.env['mail.compose.message'] + self.partner_01.message_subscribe_users(user_ids=[self.demo_user.id]) 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), + 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() @@ -35,7 +36,7 @@ class TestMailOptionalFollowernotifications(common.TransactionCase): 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\ + 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) @@ -48,7 +49,7 @@ class TestMailOptionalFollowernotifications(common.TransactionCase): ('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\ + 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/mail_compose_message.py b/mail_optional_follower_notification/wizard/mail_compose_message.py index 0153bfe6..d90bb4b7 100644 --- a/mail_optional_follower_notification/wizard/mail_compose_message.py +++ b/mail_optional_follower_notification/wizard/mail_compose_message.py @@ -2,7 +2,7 @@ # Copyright 2016 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api +from odoo import models, fields, api class MailComposeMessage(models.TransientModel): diff --git a/mail_optional_follower_notification/wizard/mail_compose_message_view.xml b/mail_optional_follower_notification/wizard/mail_compose_message_view.xml index 62078101..b4ba5194 100644 --- a/mail_optional_follower_notification/wizard/mail_compose_message_view.xml +++ b/mail_optional_follower_notification/wizard/mail_compose_message_view.xml @@ -1,5 +1,5 @@ - + mail.compose.message.form (mail_optional_autofollow) @@ -15,4 +15,4 @@ - \ No newline at end of file + \ No newline at end of file