mail_usability: add intermediary level to notify_email parameter of res.partner

This commit is contained in:
Alexis de Lattre
2017-06-22 19:28:49 +02:00
committed by Chafique
parent d3cb8aeb79
commit 8ed3ed02f9
3 changed files with 46 additions and 0 deletions

View File

@@ -1 +1,3 @@
# -*- coding: utf-8 -*-
from . import mail

View File

@@ -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',

43
mail_usability/mail.py Normal file
View File

@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-2017 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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)