[FIX] account,mail: default purchase mail alias non-ascii
* Change the `addons/account/i18n/vi.po` PO file to replace the translation of `Vendor Bill` like msgids from `Công nợ nhà cung cấp` to ` by `Hóa đơn Nhà cung cấp`, there should be 3. What's matter is the `đ` character. * Create a brand new Vietnamese database (using `-l vi_VN` and `--load-language=vi_VN`) * Install Invoicing (`account`), an email alias constraint is raised. > You cannot use anything else than unaccented latin characters in the > alias address. During the installation of the invoicing module, an email alias is created for every journal account of purchase type. The alias is created using the current journal name. Here the journal name is `Hóa đơn Nhà cung cấp`, as mail aliases should only contain ascii characters, we attempt to remove the accents. The `tools.misc.remove_accents` successfully remove most of them but the `đ` character is left as-is, the final alias is `hoa-đon-nha-cung-cap` which is invalid as it contains some non-ascii characters. The `remove_accents` function uses the [NFKD] Unicode Compatibility Decomposition Normalization Form. This normalization process unify all abstract equivalent characters, i.e. characters only different by font or rotation. While this normalization process helps to transcript a lot of characters to their ascii compatibility equivalent, some 118,230 other non-ascii characters (mainly from the Chinese and Japanese scripts) are left as-is as they lack an ascii compatibility equivalent. The solution has been to not use the journal name but rather the journal code or journal type as email alias when the name is unsafe. The journal code is a short version of the name, the journal type is not translatable so is always ascii. One additional watchdog has been added to the sanitization function of email aliases so non-ascii characters are replaced with a '?' which is an authorized character in emails local-part. [NFKD] https://unicode.org/reports/tr15/ Closes #55492 Closes #55493 closes odoo/odoo#58279 X-original-commit: 8dc85be3821cf26226cd0bf4ce2b6739e68fc66f Signed-off-by: Simon Goffin (sig) <sig@openerp.com> Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com> Co-authored-by: Thong Le <thongthele@users.no-reply.github.com>
This commit is contained in:
committed by
Goffin Simon
co-authored by
Thong Le
parent
103d8f012e
commit
33bd1a951a
@@ -3,8 +3,12 @@ from odoo import api, fields, models, _
|
||||
from odoo.osv import expression
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.addons.base.models.res_bank import sanitize_account_number
|
||||
from odoo.tools import remove_accents
|
||||
import logging
|
||||
import re
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AccountJournalGroup(models.Model):
|
||||
_name = 'account.journal.group'
|
||||
@@ -367,7 +371,18 @@ class AccountJournal(models.Model):
|
||||
if not alias_name:
|
||||
alias_name = self.name
|
||||
if self.company_id != self.env.ref('base.main_company'):
|
||||
alias_name += '-' + re.sub("[^\w!#$%&'*+/=?^`{|}~\-]", '', str(self.company_id.name))
|
||||
alias_name += '-' + str(self.company_id.name)
|
||||
try:
|
||||
remove_accents(alias_name).encode('ascii')
|
||||
except UnicodeEncodeError:
|
||||
try:
|
||||
remove_accents(self.code).encode('ascii')
|
||||
safe_alias_name = self.code
|
||||
except UnicodeEncodeError:
|
||||
safe_alias_name = self.type
|
||||
_logger.warning("Cannot use '%s' as email alias, fallback to '%s'",
|
||||
alias_name, safe_alias_name)
|
||||
alias_name = safe_alias_name
|
||||
return {
|
||||
'alias_defaults': {'move_type': type == 'purchase' and 'in_invoice' or 'out_invoice', 'company_id': self.company_id.id, 'journal_id': self.id},
|
||||
'alias_parent_thread_id': self.id,
|
||||
|
||||
@@ -142,6 +142,7 @@ class Alias(models.Model):
|
||||
name already exists an UserError is raised. """
|
||||
sanitized_name = remove_accents(name).lower().split('@')[0]
|
||||
sanitized_name = re.sub(r'[^\w+.]+', '-', sanitized_name)
|
||||
sanitized_name = sanitized_name.encode('ascii', errors='replace').decode()
|
||||
|
||||
catchall_alias = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.alias')
|
||||
bounce_alias = self.env['ir.config_parameter'].sudo().get_param('mail.bounce.alias')
|
||||
|
||||
Reference in New Issue
Block a user