[FIX] analytic: plans without account but with subplan can appear
If we have an analytic plan without analytic accounts, but with subplans that do have analytic accounts, we do want them to appear in the widget. Also changed a search in a loop to a read_group closes odoo/odoo#142222 Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -147,8 +147,15 @@ class AccountAnalyticPlan(models.Model):
|
||||
|
||||
@api.depends('account_ids', 'children_ids')
|
||||
def _compute_all_analytic_account_count(self):
|
||||
plans_count = dict(
|
||||
self.env['account.analytic.account']._read_group(
|
||||
domain=[('root_plan_id', 'in', self.ids)],
|
||||
aggregates=['id:count'],
|
||||
groupby=['root_plan_id']
|
||||
)
|
||||
)
|
||||
for plan in self:
|
||||
plan.all_account_count = self.env['account.analytic.account'].search_count([('plan_id', "child_of", plan.id)])
|
||||
plan.all_account_count = plans_count.get(plan, 0)
|
||||
|
||||
@api.depends('children_ids')
|
||||
def _compute_children_count(self):
|
||||
@@ -185,7 +192,7 @@ class AccountAnalyticPlan(models.Model):
|
||||
record_account_ids = kwargs.get('existing_account_ids', [])
|
||||
project_plan, other_plans = self.env['account.analytic.plan']._get_all_plans()
|
||||
root_plans = (project_plan + other_plans).filtered(lambda p: (
|
||||
bool(p.account_ids)
|
||||
p.all_account_count > 0
|
||||
and not p.parent_id
|
||||
and p._get_applicability(**kwargs) != 'unavailable'
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user