diff options
| author | Julien Castiaux <juc@odoo.com> | 2020-08-06 11:04:16 +0000 |
|---|---|---|
| committer | Goffin Simon <sig@odoo.com> | 2020-09-22 18:57:25 +0000 |
| commit | ad2cc2fe43cb80a7ab3b0bcd08ea29aa5b403761 (patch) | |
| tree | aa89c311bc3c691da757a1cb93dc151d7a3b48cc | |
| parent | bfbc1db205de43c8c89ca882e809d578bb733ac0 (diff) | |
[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#58276
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>
| -rw-r--r-- | addons/account/models/account_journal.py | 17 | ||||
| -rw-r--r-- | addons/mail/models/mail_alias.py | 1 |
2 files changed, 17 insertions, 1 deletions
diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index 98493af3e8e..46dbb0ac76b 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -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' @@ -357,7 +361,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, diff --git a/addons/mail/models/mail_alias.py b/addons/mail/models/mail_alias.py index 3c08bb168d6..b41b267947f 100644 --- a/addons/mail/models/mail_alias.py +++ b/addons/mail/models/mail_alias.py @@ -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') |
