From 8a2be06f9638762fd721623535e63d1895e2336c Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Mon, 29 Mar 2021 20:54:58 +0000 Subject: [PATCH] [IMP] account: allow switching CoA even when draft moves have a sequence Before, we only cheked the name to know whether or not there were moves forbidding the deletion of the whole accounting to replace the CoA. This was too strict, as an accounting with only draft moves couldn't do it if some move had a sequence number (which could happend with moves that were reset to draft). If everything is in draft, we want to allow such deletion. --- addons/account/models/chart_template.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index c2072ca7f33..5b2612ed4ab 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -244,11 +244,11 @@ class AccountChartTemplate(models.Model): ).unlink() # delete account, journal, tax, fiscal position and reconciliation model - models_to_delete = ['account.reconcile.model', 'account.fiscal.position', 'account.tax', 'account.move', 'account.journal', 'account.group'] + models_to_delete = ['account.reconcile.model', 'account.fiscal.position', 'account.move.line', 'account.move', 'account.journal', 'account.tax', 'account.group'] for model in models_to_delete: res = self.env[model].sudo().search([('company_id', '=', company.id)]) if len(res): - res.unlink() + res.with_context(force_delete=True).unlink() existing_accounts.unlink() company.write({'currency_id': self.currency_id.id, @@ -339,11 +339,11 @@ class AccountChartTemplate(models.Model): the provided company (meaning hence that its chart of accounts cannot be changed anymore). """ - model_to_check = ['account.move.line', 'account.payment', 'account.bank.statement'] + model_to_check = ['account.payment', 'account.bank.statement'] for model in model_to_check: if self.env[model].sudo().search([('company_id', '=', company_id.id)], limit=1): return True - if self.env['account.move'].sudo().search([('company_id', '=', company_id.id), ('name', '!=', '/')], limit=1): + if self.env['account.move'].sudo().search([('company_id', '=', company_id.id), ('state', '!=', 'draft')], limit=1): return True return False