From 44d7a1c3b28a3d2813dba6abb1deb46a01586983 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 17 Mar 2020 19:56:02 +0100 Subject: [PATCH] [FIX+IMP] account_chart_update: Create taxes in batch With this, we gain some performance, but also prevent an error if there are template taxes that have children taxes, as Odoo standard method forces that in the same call all of them are created simultaneously, or it will enter in an infinite loop. --- account_chart_update/wizard/wizard_chart_update.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/account_chart_update/wizard/wizard_chart_update.py b/account_chart_update/wizard/wizard_chart_update.py index 1102d7c7a..8c0863bd5 100644 --- a/account_chart_update/wizard/wizard_chart_update.py +++ b/account_chart_update/wizard/wizard_chart_update.py @@ -868,18 +868,18 @@ class WizardUpdateChartsAccounts(models.TransientModel): def _update_taxes(self): """Process taxes to create/update/deactivate.""" - for wiz_tax in self.tax_ids: + # First create taxes in batch + taxes_to_create = self.tax_ids.filtered(lambda x: x.type == "new") + taxes_to_create.mapped("tax_id")._generate_tax(self.company_id) + for wiz_tax in taxes_to_create: + _logger.info(_("Created tax %s."), "'%s'" % wiz_tax.tax_id.name) + for wiz_tax in self.tax_ids.filtered(lambda x: x.type != "new"): template, tax = wiz_tax.tax_id, wiz_tax.update_tax_id # Deactivate tax if wiz_tax.type == "deleted": tax.active = False _logger.info(_("Deactivated tax %s."), "'%s'" % tax.name) continue - # Create tax - if wiz_tax.type == "new": - template._generate_tax(self.company_id) - _logger.info(_("Created tax %s."), "'%s'" % template.name) - # Update tax else: for key, value in self.diff_fields(template, tax).items(): # We defer update because account might not be created yet