diff --git a/mail_usability/__init__.py b/mail_usability/__init__.py index 40a96af..213f276 100644 --- a/mail_usability/__init__.py +++ b/mail_usability/__init__.py @@ -1 +1,3 @@ # -*- coding: utf-8 -*- + +from . import mail diff --git a/mail_usability/__manifest__.py b/mail_usability/__manifest__.py index 67058ca..c2975fc 100644 --- a/mail_usability/__manifest__.py +++ b/mail_usability/__manifest__.py @@ -20,6 +20,7 @@ Small usability improvements on mails: * remove 'sent by' in notification footer +* add a new entry *All Messages Except Notifications* to the field *Receive Inbox Notifications by Email* of partners (becomes the default value) """, 'author': 'Akretion', 'website': 'http://www.akretion.com', diff --git a/mail_usability/mail.py b/mail_usability/mail.py new file mode 100644 index 0000000..ecbadc1 --- /dev/null +++ b/mail_usability/mail.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2016-2017 Akretion (http://www.akretion.com) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import models, fields, api + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + notify_email = fields.Selection( + selection_add=[ + ('all_except_notification', 'All Messages Except Notifications')], + default='all_except_notification') + + @api.multi + def _notify( + self, message, force_send=False, send_after_commit=True, + user_signature=True): + if message.message_type == 'notification': + message_sudo = message.sudo() + email_channels = message.channel_ids.filtered( + lambda channel: channel.email_send) + bad_email = message_sudo.author_id and\ + message_sudo.author_id.email or message.email_from + self.sudo().search([ + '|', + ('id', 'in', self.ids), + ('channel_ids', 'in', email_channels.ids), + ('email', '!=', bad_email), + ('notify_email', '=', 'always')])._notify_by_email( + message, force_send=force_send, + send_after_commit=send_after_commit, + user_signature=user_signature) + self._notify_by_chat(message) + return True + else: + return super(ResPartner, self)._notify( + message, force_send=force_send, + send_after_commit=send_after_commit, + user_signature=user_signature)