2
0

[FIX] account_chart_update: Fetch account code digits correctly

This commit is contained in:
Pedro M. Baeza 2017-11-02 17:34:58 +01:00 committed by Luis J. Salvatierra
parent 7093779041
commit cf714c11f8
2 changed files with 5 additions and 24 deletions

View File

@ -8,7 +8,7 @@
{ {
'name': "Detect changes and update the Account Chart from a template", 'name': "Detect changes and update the Account Chart from a template",
"summary": "Wizard to update a company's account chart from a template", "summary": "Wizard to update a company's account chart from a template",
'version': "10.0.1.0.0", 'version': "10.0.1.0.1",
'author': "Tecnativa, " 'author': "Tecnativa, "
"BCIM, " "BCIM, "
"Okia, " "Okia, "

View File

@ -154,31 +154,12 @@ class WizardUpdateChartsAccounts(models.TransientModel):
@api.model @api.model
def _get_code_digits(self, company=None): def _get_code_digits(self, company=None):
"""Returns the default code size for the accounts. """Returns the number of digits for the accounts, fetched from
To figure out the number of digits of the accounts it look at the the company.
code size of the default receivable account of the company
(or user's company if any company is given).
""" """
property_obj = self.env['ir.property'] if company is None:
if not company:
company = self.env.user.company_id company = self.env.user.company_id
properties = property_obj.search( return company.accounts_code_digits or 6
[('name', '=', 'property_account_receivable'),
('company_id', '=', company.id),
('res_id', '=', False),
('value_reference', '!=', False)])
number_digits = 6
if not properties:
# Try to get a generic (no-company) property
properties = property_obj.search(
[('name', '=', 'property_account_receivable'),
('res_id', '=', False),
('value_reference', '!=', False)])
if properties:
account = property_obj.get_by_record(properties[0])
if account:
number_digits = len(account.code)
return number_digits
@api.onchange('company_id') @api.onchange('company_id')
def onchange_company_id(self): def onchange_company_id(self):