[REF] refactor the code in order to split it in several file
This commit is contained in:
committed by
Alexis de Lattre
parent
e644b27b7a
commit
39855d7b12
@@ -1,6 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import mail
|
from . import models
|
||||||
from . import tools
|
from . import wizard
|
||||||
from . import mail_template
|
|
||||||
from . import mail_message
|
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ Small usability improvements on mails:
|
|||||||
'website': 'http://www.akretion.com',
|
'website': 'http://www.akretion.com',
|
||||||
'depends': ['mail'],
|
'depends': ['mail'],
|
||||||
'data': [
|
'data': [
|
||||||
'mail_view.xml',
|
'views/mail_view.xml',
|
||||||
'mail_data.xml',
|
'data/mail_data.xml',
|
||||||
|
'wizard/email_template_preview_view.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
# -*- 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')
|
|
||||||
|
|
||||||
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
|
|
||||||
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)
|
|
||||||
# Never auto delete notification email
|
|
||||||
# fucking to hard to debug when message have been delete
|
|
||||||
res['auto_delete'] = False
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
class TemplatePreview(models.TransientModel):
|
|
||||||
_inherit = "email_template.preview"
|
|
||||||
|
|
||||||
res_id = fields.Integer(compute='_compute_res_id')
|
|
||||||
object_id = fields.Reference(selection='_reference_models')
|
|
||||||
|
|
||||||
@api.model
|
|
||||||
def default_get(self, fields):
|
|
||||||
result = super(TemplatePreview, self).default_get(fields)
|
|
||||||
if result.get('model_id'):
|
|
||||||
model = self.env['ir.model'].browse(result['model_id'])
|
|
||||||
result['object_id'] = model.model
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _reference_models(self):
|
|
||||||
result = self.default_get(['model_id'])
|
|
||||||
if result.get('model_id'):
|
|
||||||
model = self.env['ir.model'].browse(result['model_id'])
|
|
||||||
return [(model.model, model.name)]
|
|
||||||
else:
|
|
||||||
models = self.env['ir.model'].search([('state', '!=', 'manual')])
|
|
||||||
return [(model.model, model.name)
|
|
||||||
for model in models
|
|
||||||
if not model.model.startswith('ir.')]
|
|
||||||
|
|
||||||
@api.depends('object_id')
|
|
||||||
def _compute_res_id(self):
|
|
||||||
for record in self:
|
|
||||||
if self.object_id:
|
|
||||||
record.res_id = self.object_id.id
|
|
||||||
|
|
||||||
def send(self):
|
|
||||||
template = self.env['mail.template'].browse(
|
|
||||||
self._context['template_id'])
|
|
||||||
template.send_mail(
|
|
||||||
self.res_id, force_send=True, raise_exception=True)
|
|
||||||
|
|
||||||
|
|
||||||
class MailThread(models.AbstractModel):
|
|
||||||
_inherit = 'mail.thread'
|
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@api.returns('self', lambda value: value.id)
|
|
||||||
def message_post(self, body='', subject=None, message_type='notification',
|
|
||||||
subtype=None, parent_id=False, attachments=None,
|
|
||||||
content_subtype='html', **kwargs):
|
|
||||||
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)
|
|
||||||
7
mail_usability/models/__init__.py
Normal file
7
mail_usability/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import mail
|
||||||
|
from . import tools
|
||||||
|
from . import mail_template
|
||||||
|
from . import mail_message
|
||||||
|
from . import res_partner
|
||||||
26
mail_usability/models/mail.py
Normal file
26
mail_usability/models/mail.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# -*- 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, api
|
||||||
|
|
||||||
|
|
||||||
|
class MailThread(models.AbstractModel):
|
||||||
|
_inherit = 'mail.thread'
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
@api.returns('self', lambda value: value.id)
|
||||||
|
def message_post(self, body='', subject=None, message_type='notification',
|
||||||
|
subtype=None, parent_id=False, attachments=None,
|
||||||
|
content_subtype='html', **kwargs):
|
||||||
|
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)
|
||||||
51
mail_usability/models/res_partner.py
Normal file
51
mail_usability/models/res_partner.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2016-2019 Akretion (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
|
||||||
|
|
||||||
|
|
||||||
|
class ResPartner(models.Model):
|
||||||
|
_inherit = 'res.partner'
|
||||||
|
|
||||||
|
notify_email = fields.Selection(
|
||||||
|
selection_add=[
|
||||||
|
('all_except_notification', 'All Messages Except Notifications')],
|
||||||
|
default='all_except_notification')
|
||||||
|
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
# Never auto delete notification email
|
||||||
|
# fucking to hard to debug when message have been delete
|
||||||
|
res['auto_delete'] = False
|
||||||
|
return res
|
||||||
21
mail_usability/views/mail_view.xml
Normal file
21
mail_usability/views/mail_view.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_mail_tree" model="ir.ui.view">
|
||||||
|
<field name="model">mail.mail</field>
|
||||||
|
<field name="inherit_id" ref="mail.view_mail_tree"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="email_from" position="replace"/>
|
||||||
|
<field name="date" position="after">
|
||||||
|
<field name="email_from"/>
|
||||||
|
<field name="email_to"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
3
mail_usability/wizard/__init__.py
Normal file
3
mail_usability/wizard/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import email_template_preview
|
||||||
44
mail_usability/wizard/email_template_preview.py
Normal file
44
mail_usability/wizard/email_template_preview.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2019 Akretion (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
|
||||||
|
|
||||||
|
|
||||||
|
class TemplatePreview(models.TransientModel):
|
||||||
|
_inherit = "email_template.preview"
|
||||||
|
|
||||||
|
res_id = fields.Integer(compute='_compute_res_id')
|
||||||
|
object_id = fields.Reference(selection='_reference_models')
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields):
|
||||||
|
result = super(TemplatePreview, self).default_get(fields)
|
||||||
|
if result.get('model_id'):
|
||||||
|
model = self.env['ir.model'].browse(result['model_id'])
|
||||||
|
result['object_id'] = model.model
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _reference_models(self):
|
||||||
|
result = self.default_get(['model_id'])
|
||||||
|
if result.get('model_id'):
|
||||||
|
model = self.env['ir.model'].browse(result['model_id'])
|
||||||
|
return [(model.model, model.name)]
|
||||||
|
else:
|
||||||
|
models = self.env['ir.model'].search([('state', '!=', 'manual')])
|
||||||
|
return [(model.model, model.name)
|
||||||
|
for model in models
|
||||||
|
if not model.model.startswith('ir.')]
|
||||||
|
|
||||||
|
@api.depends('object_id')
|
||||||
|
def _compute_res_id(self):
|
||||||
|
for record in self:
|
||||||
|
if self.object_id:
|
||||||
|
record.res_id = self.object_id.id
|
||||||
|
|
||||||
|
def send(self):
|
||||||
|
template = self.env['mail.template'].browse(
|
||||||
|
self._context['template_id'])
|
||||||
|
template.send_mail(
|
||||||
|
self.res_id, force_send=True, raise_exception=True)
|
||||||
@@ -1,24 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
|
||||||
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
||||||
-->
|
|
||||||
|
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="view_mail_tree" model="ir.ui.view">
|
|
||||||
<field name="name">mail_usability.mail.tree</field>
|
|
||||||
<field name="model">mail.mail</field>
|
|
||||||
<field name="inherit_id" ref="mail.view_mail_tree"/>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<field name="email_from" position="replace"/>
|
|
||||||
<field name="date" position="after">
|
|
||||||
<field name="email_from"/>
|
|
||||||
<field name="email_to"/>
|
|
||||||
</field>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="email_template_preview_form" model="ir.ui.view">
|
<record id="email_template_preview_form" model="ir.ui.view">
|
||||||
<field name="model">email_template.preview</field>
|
<field name="model">email_template.preview</field>
|
||||||
<field name="inherit_id" ref="mail.email_template_preview_form"/>
|
<field name="inherit_id" ref="mail.email_template_preview_form"/>
|
||||||
@@ -38,4 +20,5 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
Reference in New Issue
Block a user