[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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
@@ -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 = ''
|
||||
|
||||
@@ -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;">
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user