Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Project

Entity: project.project

Compute Method: _compute_task_count

Inputs Method Outputs
  • id
project_and_state_counts = self.env['project.task'].with_context(
            active_test=any(project.active for project in self)
        )._read_group(
            [('project_id', 'in', self.ids), ('display_in_project', '=', True)],
            ['project_id', 'state'],
            ['__count'],
        )
task_counts_per_project_id = defaultdict(lambda: {
            'open_task_count': 0,
            'closed_task_count': 0,
        })
for project, state, count in project_and_state_counts:
            task_counts_per_project_id[project.id]['closed_task_count' if state in CLOSED_STATES else 'open_task_count'] += count
for project in self:
            open_task_count, closed_task_count = task_counts_per_project_id[project.id].values()
            project.open_task_count = open_task_count
            project.closed_task_count = closed_task_count
            project.task_count = open_task_count + closed_task_count

Back to entity