summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2019-10-23 12:56:36 +0000
committerThibault Delavallée <tde@odoo.com>2019-11-29 13:35:14 +0000
commitb9a22d2f24e587894c12bf7ad289fcddcea8a823 (patch)
tree4b958db8a774c45b51a5a7a80b817d50695643cb
parent351b0ca6f4f493fed3542c8f52e8ec70ee622b7e (diff)
[IMP] mail: add computed fields for company emails
Purpose of this commit is to give a way to access to company email and catchall with formatting. Those will be used in various automated emails. Indeed currently several templates use either ``company_id.partner_id.email``, ``company_id.email``, or even don't provide fallback values. With this commit from a company record people will be able to use * a correctly formatted catchall: ``"My Company Name" <catchall_alias@catchall_domain>`` * an email_formatted field like partner email_formatted that is either its partner-related email_formatted value, or formatted catchall if its partner is not correctly configured; Various calls to mail creation are updated accordingly. Task ID 1853147 PR #32243
-rw-r--r--addons/mail/controllers/bus.py2
-rw-r--r--addons/mail/models/mail_channel.py2
-rw-r--r--addons/mail/models/mail_message.py4
-rw-r--r--addons/mail/models/res_company.py23
-rw-r--r--addons/survey/data/mail_template_data.xml2
-rw-r--r--addons/test_mail/tests/test_mail_channel.py2
-rw-r--r--addons/website_slides/models/slide_slide.py2
7 files changed, 26 insertions, 11 deletions
diff --git a/addons/mail/controllers/bus.py b/addons/mail/controllers/bus.py
index cecf83eb1b7..81f1700987d 100644
--- a/addons/mail/controllers/bus.py
+++ b/addons/mail/controllers/bus.py
@@ -47,7 +47,7 @@ class MailChatController(BusController):
email_from = author.email_formatted
else: # If Public User, use catchall email from company
author_id = False
- email_from = mail_channel.anonymous_name or mail_channel.create_uid.company_id.catchall
+ email_from = mail_channel.anonymous_name or mail_channel.create_uid.company_id.catchall_formatted
# post a message without adding followers to the channel. email_from=False avoid to get author from email data
body = tools.plaintext2html(message_content)
message = mail_channel.with_context(mail_create_nosubscribe=True).message_post(author_id=author_id,
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py
index 83727722692..a8440322c2b 100644
--- a/addons/mail/models/mail_channel.py
+++ b/addons/mail/models/mail_channel.py
@@ -420,7 +420,7 @@ class Channel(models.Model):
create_values = {
'body_html': view.render({'channel': self, 'partner': partner}, engine='ir.qweb', minimal_qcontext=True),
'subject': _("Guidelines of channel %s") % self.name,
- 'email_from': partner.company_id.catchall or partner.company_id.email,
+ 'email_from': partner.company_id.catchall_formatted or partner.company_id.email,
'recipient_ids': [(4, partner.id)]
}
mail = self.env['mail.mail'].create(create_values)
diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py
index 1262ccf8437..0bcc082fee5 100644
--- a/addons/mail/models/mail_message.py
+++ b/addons/mail/models/mail_message.py
@@ -836,7 +836,7 @@ class Message(models.Model):
if self.env.user.partner_id.email:
email_from = tools.formataddr((self.env.user.partner_id.name, self.env.user.partner_id.email))
else:
- email_from = self.env.company.catchall
+ email_from = self.env.company.catchall_formatted
body_html = tools.append_content_to_html('<div>%s</div>' % tools.ustr(comment), msg.body, plaintext=False)
vals = {
@@ -924,7 +924,7 @@ class Message(models.Model):
partner_ids=moderator.partner_id.ids,
subject=_('Message are pending moderation'), # tocheck: target language
body=template.render({'record': moderator.partner_id}, engine='ir.qweb', minimal_qcontext=True),
- email_from=moderator.company_id.catchall or moderator.company_id.email,
+ email_from=moderator.company_id.catchall_formatted or moderator.company_id.email,
)
# ------------------------------------------------------
diff --git a/addons/mail/models/res_company.py b/addons/mail/models/res_company.py
index e1223bf3192..3572c903d0e 100644
--- a/addons/mail/models/res_company.py
+++ b/addons/mail/models/res_company.py
@@ -1,22 +1,37 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import api, models, fields
+from odoo import api, models, fields, tools
class Company(models.Model):
_name = 'res.company'
_inherit = 'res.company'
- catchall = fields.Char(string="Catchall Email", compute="_compute_catchall")
+ catchall_email = fields.Char(string="Catchall Email", compute="_compute_catchall")
+ catchall_formatted = fields.Char(string="Catchall", compute="_compute_catchall")
+ email_formatted = fields.Char(string="Formatted Email", compute="_compute_email_formatted")
+ @api.depends('name')
def _compute_catchall(self):
ConfigParameter = self.env['ir.config_parameter'].sudo()
alias = ConfigParameter.get_param('mail.catchall.alias')
domain = ConfigParameter.get_param('mail.catchall.domain')
if alias and domain:
for company in self:
- company.catchall = '%s@%s' % (alias, domain)
+ company.catchall_email = '%s@%s' % (alias, domain)
+ company.catchall_formatted = tools.formataddr((company.name, company.catchall_email))
else:
for company in self:
- company.catchall = ''
+ company.catchall_email = ''
+ company.catchall_formatted = ''
+
+ @api.depends('partner_id.email_formatted', 'catchall_formatted')
+ def _compute_email_formatted(self):
+ for company in self:
+ if company.partner_id.email_formatted:
+ company.email_formatted = company.partner_id.email_formatted
+ elif company.catchall_formatted:
+ company.email_formatted = company.catchall_formatted
+ else:
+ company.email_formatted = ''
diff --git a/addons/survey/data/mail_template_data.xml b/addons/survey/data/mail_template_data.xml
index 96506fb928a..5c5d8fecc33 100644
--- a/addons/survey/data/mail_template_data.xml
+++ b/addons/survey/data/mail_template_data.xml
@@ -42,7 +42,7 @@
<field name="name">Survey: Send certification by email</field>
<field name="model_id" ref="survey.model_survey_user_input"/>
<field name="subject">Certification: ${object.survey_id.display_name}</field>
- <field name="email_from">${(object.survey_id.create_uid.email_formatted or user.email_formatted or user.company_id.catchall) |safe}</field>
+ <field name="email_from">${(object.survey_id.create_uid.email_formatted or user.email_formatted or user.company_id.catchall_formatted) |safe}</field>
<field name="email_to">${(object.partner_id.email_formatted or object.email) |safe}</field>
<field name="body_html" type="xml">
<div style="background:#F0F0F0;color:#515166;padding:10px 0px;font-family:Arial,Helvetica,sans-serif;font-size:14px;">
diff --git a/addons/test_mail/tests/test_mail_channel.py b/addons/test_mail/tests/test_mail_channel.py
index 436c9a963a1..5dadf2690b7 100644
--- a/addons/test_mail/tests/test_mail_channel.py
+++ b/addons/test_mail/tests/test_mail_channel.py
@@ -263,7 +263,7 @@ class TestChannelModeration(TestMailCommon):
self.assertEqual(mail.author_id, self.partner_employee)
self.assertEqual(mail.subject, 'Guidelines of channel %s' % self.channel_1.name)
self.assertEqual(mail.state, 'outgoing')
- self.assertEqual(mail.email_from, self.user_employee.company_id.catchall)
+ self.assertEqual(mail.email_from, self.user_employee.company_id.catchall_formatted)
self.assertEqual(self._new_mails.mapped('recipient_ids'), self.partner_employee | self.partner_portal)
def test_send_guidelines_crash(self):
diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py
index 78296759ecc..0a61291bb2c 100644
--- a/addons/website_slides/models/slide_slide.py
+++ b/addons/website_slides/models/slide_slide.py
@@ -503,7 +503,7 @@ class Slide(models.Model):
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
for record in self:
if self.env.user.has_group('base.group_portal'):
- mail_ids.append(self.channel_id.share_template_id.with_context(user=self.env.user, email=email, base_url=base_url, fullscreen=fullscreen).sudo().send_mail(record.id, notif_layout='mail.mail_notification_light', email_values={'email_from': self.env['res.company'].catchall or self.env['res.company'].email, 'email_to': email}))
+ mail_ids.append(self.channel_id.share_template_id.with_context(user=self.env.user, email=email, base_url=base_url, fullscreen=fullscreen).sudo().send_mail(record.id, notif_layout='mail.mail_notification_light', email_values={'email_from': self.env.company.catchall_formatted or self.env.company.email, 'email_to': email}))
else:
mail_ids.append(self.channel_id.share_template_id.with_context(user=self.env.user, email=email, base_url=base_url, fullscreen=fullscreen).send_mail(record.id, notif_layout='mail.mail_notification_light', email_values={'email_to': email}))
return mail_ids