From 85632d7639279bd801355c0fd8b0e8cb4e77dded Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 9 Feb 2023 13:24:02 +0000 Subject: [PATCH] [FIX] account_financial_report: endless installation Installing the module in a DB with more than 50000 accounts and groups made the install stall. It turns out this method's implementation produced almost endless recursion. it was also depending on some fields that never were used. Now it depends on the parent path, so when one group is moved to another parent, its computed accounts are recomputed, and parents' too, recursively. Now, the method is much more performant, and the module gets installed in the same DB in 30s. @moduon MT-1900 Co-authored-by: Eduardo De Miguel --- account_financial_report/models/account_group.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/account_financial_report/models/account_group.py b/account_financial_report/models/account_group.py index 726765cd..45938cc5 100644 --- a/account_financial_report/models/account_group.py +++ b/account_financial_report/models/account_group.py @@ -16,6 +16,7 @@ class AccountGroup(models.Model): ) compute_account_ids = fields.Many2many( "account.account", + recursive=True, compute="_compute_group_accounts", string="Compute accounts", store=True, @@ -58,16 +59,11 @@ class AccountGroup(models.Model): group.level = group.parent_id.level + 1 @api.depends( - "code_prefix_start", "account_ids", - "account_ids.code", - "group_child_ids", - "group_child_ids.account_ids.code", + "group_child_ids.compute_account_ids", ) def _compute_group_accounts(self): - account_obj = self.env["account.account"] - accounts = account_obj.search([]) - for group in self: - prefix = group.code_prefix_start if group.code_prefix_start else group.name - gr_acc = accounts.filtered(lambda a: a.code.startswith(prefix)).ids - group.compute_account_ids = [(6, 0, gr_acc)] + for one in self: + one.compute_account_ids = ( + one.account_ids | one.group_child_ids.compute_account_ids + )