From 23a9ae55d8584302b7feb952d0d12439e2766470 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 11 Feb 2020 12:26:45 +0100 Subject: [PATCH] [12.0][FIX] - filter mail follower based on notify_followers option fixes: #499 --- .../models/__init__.py | 3 +- .../models/mail_followers.py | 22 +++++++++++++ .../models/mail_message.py | 32 ------------------- .../models/res_partner.py | 22 ------------- .../readme/CONTRIBUTORS.rst | 1 + 5 files changed, 24 insertions(+), 56 deletions(-) create mode 100644 mail_optional_follower_notification/models/mail_followers.py delete mode 100644 mail_optional_follower_notification/models/mail_message.py delete mode 100644 mail_optional_follower_notification/models/res_partner.py diff --git a/mail_optional_follower_notification/models/__init__.py b/mail_optional_follower_notification/models/__init__.py index b3d15f460..aa103645d 100644 --- a/mail_optional_follower_notification/models/__init__.py +++ b/mail_optional_follower_notification/models/__init__.py @@ -1,4 +1,3 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from . import mail_message -from . import res_partner +from . import mail_followers diff --git a/mail_optional_follower_notification/models/mail_followers.py b/mail_optional_follower_notification/models/mail_followers.py new file mode 100644 index 000000000..a3d8f4602 --- /dev/null +++ b/mail_optional_follower_notification/models/mail_followers.py @@ -0,0 +1,22 @@ +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models, api + + +class MailFollowers(models.Model): + _inherit = 'mail.followers' + + @api.multi + def _get_recipient_data(self, records, subtype_id, pids=None, cids=None): + res = super()._get_recipient_data( + records, subtype_id, pids=pids, cids=cids + ) + if 'notify_followers' in self._context and not self._context.get( + 'notify_followers' + ): + return filter( + lambda partner_id, partner_ids=pids: partner_id[0] + in partner_ids, res + ) + return res diff --git a/mail_optional_follower_notification/models/mail_message.py b/mail_optional_follower_notification/models/mail_message.py deleted file mode 100644 index 7afe71308..000000000 --- a/mail_optional_follower_notification/models/mail_message.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2016 ACSONE SA/NV () -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import models, api - - -class MailMessage(models.Model): - _inherit = 'mail.message' - - @api.model - def create(self, values): - ctx = self.env.context.copy() - if not ctx.get('notify_followers') and values.get('partner_ids'): - partner_list = self.resolve_2many_commands( - 'partner_ids', values.get('partner_ids'), fields=['id']) - ctx['force_partners_to_notify'] = [d['id'] for d in partner_list] - return super(MailMessage, self.with_context(ctx)).create(values) - - @api.multi - def _notify(self, record, msg_vals, force_send=False, - send_after_commit=True, model_description=False, - mail_auto_delete=True): - res = super()._notify( - record, msg_vals, force_send=force_send, - send_after_commit=send_after_commit, - model_description=model_description, - mail_auto_delete=mail_auto_delete) - if self.env.context.get('force_partners_to_notify'): - # Needaction only for recipients - self.needaction_partner_ids = [ - (6, 0, self.env.context.get('force_partners_to_notify'))] - return res diff --git a/mail_optional_follower_notification/models/res_partner.py b/mail_optional_follower_notification/models/res_partner.py deleted file mode 100644 index 6ca4f5e9c..000000000 --- a/mail_optional_follower_notification/models/res_partner.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2016 ACSONE SA/NV () -# 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 index bea4300dc..c50509dc0 100644 --- a/mail_optional_follower_notification/readme/CONTRIBUTORS.rst +++ b/mail_optional_follower_notification/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Adrien Peiffer * Laurent Mignon * Andrea Stirpe +* Souheil Bejaoui