From 96a06df867fcef1fd24a1798bd5d6decc423933b Mon Sep 17 00:00:00 2001 From: "Benjamin Hanquin (beha)" Date: Fri, 19 Jan 2024 14:36:27 +0000 Subject: [PATCH] [FIX] account_group: Avoid parent_id recursion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: Infinite loop in Trial Balance. Analyze: The infinite loop is due to account_reports.models.account_report.AccountReport.get_account_codes `while group:` loop if a recursion exist in group.parent_id there is an infinite loop. Fix: Ensure the no recursion constrains on parent_id in account_reports. Related task: opw-3665256 closes odoo/odoo#156410 X-original-commit: 0ce8efbc78853876b9768b6500a4998745ecc070 Signed-off-by: Benjamin Hanquin (beha) Signed-off-by: William André (wan) --- addons/account/i18n/account.pot | 7 +++++++ addons/account/models/account_account.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 3c8b047f7b2..918c0650cce 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -15933,6 +15933,13 @@ msgid "" "move and post it after." msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/account_account.py:0 +#, python-format +msgid "You cannot create recursive groups." +msgstr "" + #. module: account #. odoo-python #: code:addons/account/models/account_move_line.py:0 diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 22cf2b8caaf..9b620009fbe 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -905,6 +905,11 @@ class AccountGroup(models.Model): del vals['code_prefix_start'] return vals + @api.constrains('parent_id') + def _check_parent_not_circular(self): + if not self._check_recursion(): + raise ValidationError(_("You cannot create recursive groups.")) + @api.model_create_multi def create(self, vals_list): groups = super().create([self._sanitize_vals(vals) for vals in vals_list])