[12.0][MIG] mail_usability

This commit is contained in:
Chafique
2020-10-26 11:30:23 +01:00
committed by Alexis de Lattre
parent 70d7cbdfda
commit f752fbc9f3
13 changed files with 61 additions and 107 deletions

View File

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

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-2017 Akretion (http://www.akretion.com)
# Copyright 2016-2017 Akretion France (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -31,9 +30,7 @@ class MailThread(models.AbstractModel):
if not 'mail_create_nosubscribe' in self._context:
# Do not implicitly follow an object by just sending a message
self = self.with_context(mail_create_nosubscribe=True)
return super(MailThread,
self.with_context(mail_create_nosubscribe=True)
).message_post(
body=body, subject=subject, message_type=message_type,
subtype=subtype, parent_id=parent_id, attachments=attachments,
content_subtype=content_subtype, **kwargs)
return super(MailThread, self).message_post(
body=body, subject=subject, message_type=message_type,
subtype=subtype, parent_id=parent_id, attachments=attachments,
content_subtype=content_subtype, **kwargs)

View File

@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Akretion (http://www.akretion.com).
# Copyright 2019 Akretion France (http://www.akretion.com)
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models
from odoo import models
class MailMessage(models.Model):

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Akretion (http://www.akretion.com).
# Copyright 2018 Akretion France (http://www.akretion.com)
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,52 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-2019 Akretion (http://www.akretion.com)
# Copyright 2016-2019 Akretion France (http://www.akretion.com)
# @author Sébastien BEAU <sebastien.beau@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
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')
opt_out = fields.Boolean(track_visibility='onchange')
def _should_be_notify_by_email(self, message):
if message.message_type == 'notification':
if self.notify_email == 'always':
return True
else:
return False
else:
return True
def _notify_by_email(
self, message, force_send=False, send_after_commit=True,
user_signature=True):
# use an empty layout for notification by default
@api.model
def _notify(self, message, rdata, record, force_send=False,
send_after_commit=True, model_description=False,
mail_auto_delete=True):
# use an empty layout for notification by default
if not self._context.get('custom_layout'):
self = self.with_context(
custom_layout='mail_usability.mail_template_notification')
# Filter the partner that should receive the notification
filtered_partners = self.filtered(
lambda p: p._should_be_notify_by_email(message)
)
return super(ResPartner, filtered_partners)._notify_by_email(
message, force_send=force_send,
send_after_commit=send_after_commit,
user_signature=user_signature)
def _notify_prepare_email_values(self, message):
res = super(ResPartner, self)._notify_prepare_email_values(message)
self = self.with_context(
custom_layout='mail_usability.mail_template_notification')
# Never auto delete notification email
# fucking to hard to debug when message have been delete
res['auto_delete'] = False
return res
mail_auto_delete = False
return super(ResPartner, self)._notify(
message=message, rdata=rdata, record=record,
force_send=force_send, send_after_commit=send_after_commit,
model_description=model_description, mail_auto_delete=mail_auto_delete)

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Akretion (http://www.akretion.com).
# Copyright 2018 Akretion France (http://www.akretion.com)
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -41,5 +40,4 @@ if os.getenv('LOG_STYLE_SANITIZE'):
for (key, val) in valid_styles.iteritems())
else:
del el.attrib['style']
import pdb; pdb.set_trace()
_Cleaner.parse_style = parse_style