[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 <edu@moduon.team>
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user