[REF] account: remove option to change number of digits
Remove the possibility to define the number of digits for the accounts in the accounting settings. People can do a export/import to do that. Was PR #16587. Was task 32750
This commit is contained in:
@@ -597,15 +597,17 @@ class AccountJournal(models.Model):
|
||||
:return: mapping of field names and values
|
||||
:rtype: dict
|
||||
'''
|
||||
|
||||
digits = 6
|
||||
acc = self.env['account.account'].search([('company_id', '=', company.id)], limit=1)
|
||||
if acc:
|
||||
digits = len(acc.code)
|
||||
# Seek the next available number for the account code
|
||||
code_digits = company.accounts_code_digits or 0
|
||||
if type == 'bank':
|
||||
account_code_prefix = company.bank_account_code_prefix or ''
|
||||
else:
|
||||
account_code_prefix = company.cash_account_code_prefix or company.bank_account_code_prefix or ''
|
||||
for num in range(1, 100):
|
||||
new_code = str(account_code_prefix.ljust(code_digits - 1, '0')) + str(num)
|
||||
new_code = str(account_code_prefix.ljust(digits - 1, '0')) + str(num)
|
||||
rec = self.env['account.account'].search([('code', '=', new_code), ('company_id', '=', company.id)], limit=1)
|
||||
if not rec:
|
||||
break
|
||||
|
||||
@@ -885,7 +885,6 @@ class WizardMultiChartsAccounts(models.TransientModel):
|
||||
|
||||
company = self.company_id
|
||||
self.company_id.write({'currency_id': self.currency_id.id,
|
||||
'accounts_code_digits': self.code_digits,
|
||||
'anglo_saxon_accounting': self.use_anglo_saxon,
|
||||
'bank_account_code_prefix': self.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': self.cash_account_code_prefix,
|
||||
|
||||
@@ -23,7 +23,6 @@ class ResCompany(models.Model):
|
||||
chart_template_id = fields.Many2one('account.chart.template', help='The chart template for the company (if any)')
|
||||
bank_account_code_prefix = fields.Char(string='Prefix of the bank accounts', oldname="bank_account_code_char")
|
||||
cash_account_code_prefix = fields.Char(string='Prefix of the cash accounts')
|
||||
accounts_code_digits = fields.Integer(string='Number of digits in an account code')
|
||||
account_sale_tax_id = fields.Many2one('account.tax', string="Default Sale Tax")
|
||||
account_purchase_tax_id = fields.Many2one('account.tax', string="Default Purchase Tax")
|
||||
tax_cash_basis_journal_id = fields.Many2one('account.journal', string="Cash Basis Journal")
|
||||
@@ -97,20 +96,16 @@ Best Regards,''')
|
||||
date_from = date_from.replace(year=date_from.year - 1)
|
||||
return {'date_from': date_from, 'date_to': date_to}
|
||||
|
||||
def get_new_account_code(self, current_code, old_prefix, new_prefix, digits):
|
||||
def get_new_account_code(self, current_code, old_prefix, new_prefix):
|
||||
digits = len(current_code)
|
||||
return new_prefix + current_code.replace(old_prefix, '', 1).lstrip('0').rjust(digits-len(new_prefix), '0')
|
||||
|
||||
def reflect_code_prefix_change(self, old_code, new_code, digits):
|
||||
def reflect_code_prefix_change(self, old_code, new_code):
|
||||
accounts = self.env['account.account'].search([('code', 'like', old_code), ('internal_type', '=', 'liquidity'),
|
||||
('company_id', '=', self.id)], order='code asc')
|
||||
for account in accounts:
|
||||
if account.code.startswith(old_code):
|
||||
account.write({'code': self.get_new_account_code(account.code, old_code, new_code, digits)})
|
||||
|
||||
def reflect_code_digits_change(self, digits):
|
||||
accounts = self.env['account.account'].search([('company_id', '=', self.id)], order='code asc')
|
||||
for account in accounts:
|
||||
account.write({'code': account.code.rstrip('0').ljust(digits, '0')})
|
||||
account.write({'code': self.get_new_account_code(account.code, old_code, new_code)})
|
||||
|
||||
@api.multi
|
||||
def _validate_fiscalyear_lock(self, values):
|
||||
@@ -129,15 +124,12 @@ Best Regards,''')
|
||||
|
||||
# Reflect the change on accounts
|
||||
for company in self:
|
||||
digits = values.get('accounts_code_digits') or company.accounts_code_digits
|
||||
if values.get('bank_account_code_prefix') or values.get('accounts_code_digits'):
|
||||
if values.get('bank_account_code_prefix'):
|
||||
new_bank_code = values.get('bank_account_code_prefix') or company.bank_account_code_prefix
|
||||
company.reflect_code_prefix_change(company.bank_account_code_prefix, new_bank_code, digits)
|
||||
if values.get('cash_account_code_prefix') or values.get('accounts_code_digits'):
|
||||
company.reflect_code_prefix_change(company.bank_account_code_prefix, new_bank_code)
|
||||
if values.get('cash_account_code_prefix'):
|
||||
new_cash_code = values.get('cash_account_code_prefix') or company.cash_account_code_prefix
|
||||
company.reflect_code_prefix_change(company.cash_account_code_prefix, new_cash_code, digits)
|
||||
if values.get('accounts_code_digits'):
|
||||
company.reflect_code_digits_change(digits)
|
||||
company.reflect_code_prefix_change(company.cash_account_code_prefix, new_cash_code)
|
||||
return super(ResCompany, self).write(values)
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -19,7 +19,6 @@ class ResConfigSettings(models.TransientModel):
|
||||
has_chart_of_accounts = fields.Boolean(compute='_compute_has_chart_of_accounts', string='Company has a chart of accounts')
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Template',
|
||||
domain="[('visible','=', True)]")
|
||||
code_digits = fields.Integer(string='# of Digits *', related='company_id.accounts_code_digits', help="No. of digits to use for account code")
|
||||
sale_tax_id = fields.Many2one('account.tax', string="Default Sale Tax", related='company_id.account_sale_tax_id')
|
||||
purchase_tax_id = fields.Many2one('account.tax', string="Default Purchase Tax", related='company_id.account_purchase_tax_id')
|
||||
tax_calculation_rounding_method = fields.Selection([
|
||||
@@ -69,7 +68,6 @@ class ResConfigSettings(models.TransientModel):
|
||||
'company_id': self.company_id.id,
|
||||
'chart_template_id': self.chart_template_id.id,
|
||||
'transfer_account_id': self.chart_template_id.transfer_account_id.id,
|
||||
'code_digits': self.code_digits or 6,
|
||||
'sale_tax_rate': 15.0,
|
||||
'purchase_tax_rate': 15.0,
|
||||
'complete_tax_set': self.chart_template_id.complete_tax_set,
|
||||
@@ -122,12 +120,8 @@ class ResConfigSettings(models.TransientModel):
|
||||
# related values, including the currency_id field on res_company. This in turn will trigger the recomputation
|
||||
# of account_move_line related field company_currency_id which can be slow depending on the number of entries
|
||||
# in the database. Thus, if we do not explicitly change the currency_id, we should not write it on the company
|
||||
# Same for the field `code_digits` which will trigger a write on all the account.account to complete the
|
||||
# code the missing characters to complete the desired number of digit, leading to a sql_constraint.
|
||||
if ('company_id' in values and 'currency_id' in values):
|
||||
company = self.env['res.company'].browse(values.get('company_id'))
|
||||
if company.currency_id.id == values.get('currency_id'):
|
||||
values.pop('currency_id')
|
||||
if company.accounts_code_digits == values.get('code_digits'):
|
||||
values.pop('code_digits')
|
||||
return super(ResConfigSettings, self).create(values)
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
<record id="base.main_company" model="res.company">
|
||||
<field name="bank_account_code_prefix">X1100</field>
|
||||
<field name="accounts_code_digits">7</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
|
||||
Reference in New Issue
Block a user