From ad1b376b8949b3e7666af7d0dffe75b90ca51de8 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 17 Mar 2020 20:00:09 +0100 Subject: [PATCH] [FIX+IMP] account_chart_update: Add consistency method With this, we prevent lock due to infinite loop if children taxes are matched, but not the parent one and it's marked to be created. --- account_chart_update/__manifest__.py | 2 +- .../wizard/wizard_chart_update.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/account_chart_update/__manifest__.py b/account_chart_update/__manifest__.py index c2d99a0c..f838bf2a 100644 --- a/account_chart_update/__manifest__.py +++ b/account_chart_update/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Detect changes and update the Account Chart from a template", "summary": "Wizard to update a company's account chart from a template", - "version": "13.0.1.0.1", + "version": "13.0.1.0.2", "author": "Tecnativa, BCIM, Okia, Odoo Community Association (OCA)", "website": "http://github.com/OCA/account-financial-tools", "depends": ["account"], diff --git a/account_chart_update/wizard/wizard_chart_update.py b/account_chart_update/wizard/wizard_chart_update.py index 8c0863bd..23a67e09 100644 --- a/account_chart_update/wizard/wizard_chart_update.py +++ b/account_chart_update/wizard/wizard_chart_update.py @@ -319,8 +319,38 @@ class WizardUpdateChartsAccounts(models.TransientModel): self.state = "ready" return self._reopen() + def _check_consistency(self): + """Method for assuring consistency in operations before performing + them. For now, implemented: + + - If a parent tax is tried to be created, children taxes must be + also included to be created. + + TODO: + + - Check that needed accounts in taxes/FPs are created at the same time. + - Check that needed taxes in FPs are created at the same time. + """ + taxes2create = self.tax_ids.filtered(lambda x: x.type == "new") + parents2create = taxes2create.filtered(lambda x: x.tax_id.children_tax_ids) + for parent in parents2create: + if bool( + parent.tax_id.children_tax_ids - taxes2create.mapped("tax_id") + ): # some children taxes are not included to be added + raise exceptions.UserError( + _( + "You have at least one parent tax template (%s) whose " + "children taxes are not going to be created. Aborting " + "as this will provoke an infinite loop. Please check " + "if children have been matched, but not the parent one." + ) + % parent.tax_id.name + ) + + @api.multi def action_update_records(self): """Action that creates/updates/deletes the selected elements.""" + self._check_consistency() self = self.with_context(lang=self.lang) self.rejected_new_account_number = 0 self.rejected_updated_account_number = 0