[FIX] account: use company name or id as suffix for journal alias name
Loading the demo data of Accounting app when only Japanese language is installed will raise an error because there is a non-unique alias_name Steps to reproduce: 1. - Run odoo with parameters `-d [db_name] --without-demo all --load-language ja_JP -i l10n_jp,account_accountant` (you can also install those apps using the UI but only Japanese should be installed so it will be in Japanese) - Or create a trial database on odoo.com with Accounting installed, using Japan as country and Japanese as language 2. Activate debug mode and go to Settings, scroll to the bottom and load the demo data (`デモデータをロード`, last link in 'Developer Tools') 3. A validation error is thrown Solution: When building the alias name, if the name of the journal is not in ascii, use the journal's code or type followed by the company's name. If the company's name is not ascii, use the company id as suffix Problem: When a journal with non-ascii characters in its name is created, its alias name fallbacks to the journal's code. In the demo data, two journals have the same code. It will try to create the second journal with the same alias name, violating the unicity check in `_clean_and_check_unique`. opw-2831638 closes odoo/odoo#90969 X-original-commit: 91d26b32250a74684dacad8350ac4452fa082384 Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
@@ -351,7 +351,10 @@ class AccountJournal(models.Model):
|
||||
) if string and is_encodable_as_ascii(string))
|
||||
|
||||
if journal.company_id != self.env.ref('base.main_company'):
|
||||
alias_name = f"{alias_name}-{journal.company_id.name}"
|
||||
if is_encodable_as_ascii(journal.company_id.name):
|
||||
alias_name = f"{alias_name}-{journal.company_id.name}"
|
||||
else:
|
||||
alias_name = f"{alias_name}-{journal.company_id.id}"
|
||||
|
||||
alias_values = {
|
||||
'alias_defaults': {
|
||||
@@ -368,12 +371,13 @@ class AccountJournal(models.Model):
|
||||
alias_values['alias_model_id'] = self.env['ir.model']._get('account.move').id
|
||||
alias_values['alias_parent_model_id'] = self.env['ir.model']._get('account.journal').id
|
||||
journal.alias_id = self.env['mail.alias'].sudo().create(alias_values)
|
||||
self.invalidate_cache(['alias_name'], self.ids)
|
||||
|
||||
@api.depends('name')
|
||||
def _compute_alias_domain(self):
|
||||
self.alias_domain = self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain")
|
||||
|
||||
@api.depends('alias_id')
|
||||
@api.depends('alias_id', 'alias_id.alias_name')
|
||||
def _compute_alias_name(self):
|
||||
for journal in self:
|
||||
journal.alias_name = journal.alias_id.alias_name
|
||||
|
||||
@@ -135,3 +135,25 @@ class TestAccountJournal(AccountTestInvoicingCommon):
|
||||
second_method.unlink()
|
||||
|
||||
self.assertFalse(second_method.exists())
|
||||
|
||||
def test_account_journal_alias_name(self):
|
||||
journal = self.company_data['default_journal_purchase']
|
||||
self.assertEqual(journal.alias_name, 'vendor-bills-company_1_data')
|
||||
journal.name = 'ぁ'
|
||||
journal.alias_name = False
|
||||
self.assertEqual(journal.alias_name, 'bill-company_1_data')
|
||||
journal.code = 'ぁ'
|
||||
journal.alias_name = False
|
||||
self.assertEqual(journal.alias_name, 'purchase-company_1_data')
|
||||
|
||||
company_2_id = str(self.company_data_2['company'].id)
|
||||
journal_2 = self.company_data_2['default_journal_sale']
|
||||
self.company_data_2['company'].name = 'ぁ'
|
||||
journal_2.alias_name = False
|
||||
self.assertEqual(journal_2.alias_name, 'customer-invoices-' + company_2_id)
|
||||
journal_2.name = 'ぁ'
|
||||
journal_2.alias_name = False
|
||||
self.assertEqual(journal_2.alias_name, 'inv-' + company_2_id)
|
||||
journal_2.code = 'ぁ'
|
||||
journal_2.alias_name = False
|
||||
self.assertEqual(journal_2.alias_name, 'sale-' + company_2_id)
|
||||
|
||||
Reference in New Issue
Block a user