[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) <oco@odoo.com>
Signed-off-by: Aliya Tastemirova (alta) <alta@odoo.com>
This commit is contained in:
aliya
2022-11-16 10:28:48 +01:00
parent 56fd66257c
commit 2dfcfca8fd
4 changed files with 11 additions and 5 deletions
+6
View File
@@ -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
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -36,8 +36,8 @@
<field name="property_valuation" invisible="1"/>
<field name="property_stock_valuation_account_id" options="{'no_create': True}" attrs="{'required':[('property_valuation', '=', 'real_time')]}"/>
<field name="property_stock_journal" attrs="{'required':[('property_valuation', '=', 'real_time')]}" />
<field name="property_stock_account_input_categ_id" attrs="{'required':[ ('property_valuation', '=', 'real_time')]}" />
<field name="property_stock_account_output_categ_id" attrs="{'required':[ ('property_valuation', '=', 'real_time')]}" />
<field name="property_stock_account_input_categ_id" options="{'no_create': True}" attrs="{'required':[ ('property_valuation', '=', 'real_time')]}" />
<field name="property_stock_account_output_categ_id" options="{'no_create': True}" attrs="{'required':[ ('property_valuation', '=', 'real_time')]}" />
<div colspan="2" class="alert alert-info mt16" role="status">
<b>Set other input/output accounts on specific </b><button name="%(stock.action_prod_inv_location_form)d" role="button" type="action" class="btn-link" style="padding: 0;vertical-align: baseline;" string="locations"/>.
</div>