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
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models, fields, tools
|
|
|
|
|
|
class Company(models.Model):
|
|
_name = 'res.company'
|
|
_inherit = 'res.company'
|
|
|
|
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_email = '%s@%s' % (alias, domain)
|
|
company.catchall_formatted = tools.formataddr((company.name, company.catchall_email))
|
|
else:
|
|
for company in self:
|
|
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 = ''
|