[FIX] account, point_of_sale: check existing accounting

When creating a sub company with l10n_ar, we
get a ValidationError due to the check on
existing accounting entries on root company.

Steps:

- Create a new company with l10n_ar, and
  create some moves
- Create a branch for the company and save
-> ValidationError: "Could not change the AFIP
   Responsibility of this company because there
   are already accounting entries."

In `account.res_company._existing_accounting`,
we check if there are existing move lines in
both parent and child companies, while we would
like to check only new company when it is calling
from `l10n_ar.res_company._check_accounting_info`.
With this commit, we change just change the domain
and use `self.id` instead of `self.root_id.id` and
we call `_existing_accounting` with `root_id` where
needed.

opw-3572926

closes odoo/odoo#140795

X-original-commit: 575971458d454d546d967ec4141d8c47fc28e666
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Guillaume Vanleynseele (guva) <guva@odoo.com>
This commit is contained in:
guva-odoo
2023-11-02 19:39:44 +00:00
parent 794d52c462
commit fb215afb82
4 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -172,7 +172,7 @@ class AccountChartTemplate(models.AbstractModel):
reload_template = template_code == company.chart_template
company.chart_template = template_code
if not reload_template and (not company._existing_accounting() or self.env.ref('base.module_account').demo):
if not reload_template and (not company.root_id._existing_accounting() or self.env.ref('base.module_account').demo):
for model in ('account.move',) + TEMPLATE_MODELS[::-1]:
if not company.parent_id:
self.env[model].sudo().with_context(active_test=False).search([('company_id', 'child_of', company.id)]).with_context({MODULE_UNINSTALL_FLAG: True}).unlink()
@@ -376,7 +376,7 @@ class AccountChartTemplate(models.AbstractModel):
# Set the currency to the fiscal country's currency
vals = {key: val for key, val in template_data.items() if filter_properties(key)}
if not company._existing_accounting():
if not company.root_id._existing_accounting():
if company.parent_id:
vals['currency_id'] = company.parent_id.currency_id.id
else:
+2 -2
View File
@@ -393,7 +393,7 @@ class ResCompany(models.Model):
#forbid the change of currency_id if there are already some accounting entries existing
if 'currency_id' in values and values['currency_id'] != company.currency_id.id:
if company._existing_accounting():
if company.root_id._existing_accounting():
raise UserError(_('You cannot change the currency of the company since some journal items already exist'))
return super(ResCompany, self).write(values)
@@ -534,7 +534,7 @@ class ResCompany(models.Model):
def _existing_accounting(self) -> bool:
"""Return True iff some accounting entries have already been made for the current company."""
self.ensure_one()
return bool(self.env['account.move.line'].search([('company_id', 'child_of', self.root_id.id)], limit=1))
return bool(self.env['account.move.line'].search([('company_id', 'child_of', self.id)], limit=1))
def _chart_template_selection(self):
return self.env['account.chart.template']._select_chart_template(self.country_id)
+1 -1
View File
@@ -251,7 +251,7 @@ class ResConfigSettings(models.TransientModel):
@api.depends('company_id')
def _compute_has_chart_of_accounts(self):
self.has_chart_of_accounts = bool(self.company_id.chart_template)
self.has_accounting_entries = self.company_id._existing_accounting()
self.has_accounting_entries = self.company_id.root_id._existing_accounting()
@api.onchange('group_analytic_accounting')
def onchange_analytic_accounting(self):
+1 -1
View File
@@ -192,7 +192,7 @@ class PosConfig(models.Model):
@api.depends('company_id')
def _compute_company_has_template(self):
for config in self:
config.company_has_template = config.company_id.sudo()._existing_accounting() or config.company_id.chart_template
config.company_has_template = config.company_id.root_id.sudo()._existing_accounting() or config.company_id.chart_template
def _compute_is_installed_account_accountant(self):
account_accountant = self.env['ir.module.module'].sudo().search([('name', '=', 'account_accountant'), ('state', '=', 'installed')])