From afb33cb56e025905ca7b158b7bff4fa92ad43e7e Mon Sep 17 00:00:00 2001 From: william-andre Date: Tue, 14 Nov 2023 07:50:14 +0100 Subject: [PATCH] [FIX] account: max recursion while creating taxes How to reproduce: * create a lot of taxes in batch The SQL query builder will throw a max recursion depth when building the `OR(domains)`. The solution is simply to reduce the size of the batches to avoid that error. Part-of: odoo/odoo#142017 --- addons/account/i18n/account.pot | 7 +++++ addons/account/models/account_tax.py | 41 ++++++++++++++++------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index d155508f315..bd46e113f41 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -228,6 +228,13 @@ msgstr "" msgid ").
" msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/account_tax.py:0 +#, python-format +msgid "- %(name)s in %(company)s" +msgstr "" + #. module: account #: model_terms:ir.ui.view,arch_db:account.res_config_settings_view_form msgid "- A default Customer Invoice / Vendor Bill date will be suggested." diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index df166629968..17f61f4ef18 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -4,7 +4,7 @@ from odoo.osv import expression from odoo.tools.float_utils import float_round from odoo.exceptions import UserError, ValidationError from odoo.tools.misc import clean_context, formatLang -from odoo.tools import frozendict, groupby +from odoo.tools import frozendict, groupby, split_every from collections import defaultdict from markupsafe import Markup @@ -183,24 +183,29 @@ class AccountTax(models.Model): is_used = fields.Boolean(string="Tax used", compute='_compute_is_used') repartition_lines_str = fields.Char(string="Repartition Lines", tracking=True, compute='_compute_repartition_lines_str') - @api.constrains('company_id', 'name', 'type_tax_use', 'tax_scope') + @api.constrains('company_id', 'name', 'type_tax_use', 'tax_scope', 'country_id') def _constrains_name(self): - domains = [] - for record in self: - if record.type_tax_use != 'none': - domains.append([ - ('company_id', 'child_of', record.company_id.root_id.id), - ('name', '=', record.name), - ('type_tax_use', '=', record.type_tax_use), - ('tax_scope', '=', record.tax_scope), - ('country_id', '=', record.country_id.id), - ('id', '!=', record.id), - ]) - if duplicates := self.search(expression.OR(domains)): - raise ValidationError( - _("Tax names must be unique!") - + "\n" + "\n".join(f"- {duplicate.name} in {duplicate.company_id.name}" for duplicate in duplicates) - ) + for taxes in split_every(100, self.ids, self.browse): + domains = [] + for tax in taxes: + if tax.type_tax_use != 'none': + domains.append([ + ('company_id', 'child_of', tax.company_id.root_id.id), + ('name', '=', tax.name), + ('type_tax_use', '=', tax.type_tax_use), + ('tax_scope', '=', tax.tax_scope), + ('country_id', '=', tax.country_id.id), + ('id', '!=', tax.id), + ]) + if duplicates := self.search(expression.OR(domains)): + raise ValidationError( + _("Tax names must be unique!") + + "\n" + "\n".join(_( + "- %(name)s in %(company)s", + name=duplicate.name, + company=duplicate.company_id.name, + ) for duplicate in duplicates) + ) @api.constrains('tax_group_id') def validate_tax_group_id(self):