From 2dfcfca8fd6971059b9e1062f9ff8c219ac8f214 Mon Sep 17 00:00:00 2001 From: aliya Date: Wed, 2 Nov 2022 12:59:52 +0000 Subject: [PATCH] [FIX] account: fix account creation bugs - When importing account move lines, accounts are created with `name_create`. If the `account_id` column only contains the code, like "12345", the `split_code_name` would only return a value for the name and leave the code empty. This is because the first group in the regex expects a space in the end, so "12345 " would work correctly. The code is a required field, hence the import fails. Removing \s from the first group fixes the issue and the code is saved correctly. - There should be a UserError raised in `name_create` instead of the ValueError. The message should be clearer as well. - It should not be possible to quick create an account from product category views. task-3056847 closes odoo/odoo#105815 X-original-commit: 24758778172595388c19fd0a83d93d35f2260261 Signed-off-by: Olivier Colson (oco) Signed-off-by: Aliya Tastemirova (alta) --- addons/account/i18n/account.pot | 6 ++++++ addons/account/models/account_account.py | 4 ++-- addons/account/tests/test_account_account.py | 2 +- addons/stock_account/views/product_views.xml | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 314d9b06797..bece24f1d9d 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -10214,6 +10214,12 @@ msgstr "" msgid "Period Comparison" msgstr "" +#. module: account +#: code:addons/account/models/account_account.py:0 +#, python-format +msgid "Please create new accounts from the Chart of Accounts menu." +msgstr "" + #. module: account #: code:addons/account/models/account_payment.py:0 #, python-format diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 24e76802de8..921c777cdf0 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -6,7 +6,7 @@ from bisect import bisect_left from collections import defaultdict import re -ACCOUNT_REGEX = re.compile(r'(?:(\S*\d+\S*)\s)?(.*)') +ACCOUNT_REGEX = re.compile(r'(?:(\S*\d+\S*))?(.*)') ACCOUNT_CODE_REGEX = re.compile(r'^[A-Za-z0-9.]+$') class AccountAccount(models.Model): @@ -690,7 +690,7 @@ class AccountAccount(models.Model): if 'import_file' in self.env.context: code, name = self._split_code_name(name) return self.create({'code': code, 'name': name}).name_get()[0] - raise ValueError(_("The values for the created account need to be verified.")) + raise UserError(_("Please create new accounts from the Chart of Accounts menu.")) def write(self, vals): # Do not allow changing the company_id when account_move_line already exist diff --git a/addons/account/tests/test_account_account.py b/addons/account/tests/test_account_account.py index 2ec0976fffc..63205796606 100644 --- a/addons/account/tests/test_account_account.py +++ b/addons/account/tests/test_account_account.py @@ -159,7 +159,7 @@ class TestAccountAccount(AccountTestInvoicingCommon): """name_create should only be possible when importing Code and Name should be split """ - with self.assertRaises(ValueError): + with self.assertRaises(UserError): self.env['account.account'].name_create('550003 Existing Account') account_id = self.env['account.account'].with_context(import_file=True).name_create('550003 Existing Account')[0] account = self.env['account.account'].browse(account_id) diff --git a/addons/stock_account/views/product_views.xml b/addons/stock_account/views/product_views.xml index dad42d09084..07d8098fee2 100644 --- a/addons/stock_account/views/product_views.xml +++ b/addons/stock_account/views/product_views.xml @@ -36,8 +36,8 @@ - - + +
Set other input/output accounts on specific