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

Module: Project Task Product

Entity: product.template

Compute Method: _compute_task_count

Inputs Method Outputs
  • product_variant_ids
variants = self.mapped("product_variant_ids")
task_data = self.env["project.task"]._read_group(
            [("product_id", "in", variants.ids)],
            groupby=["product_id"],
            aggregates=["__count"],
        )
mapped = {product.id: count for product, count in task_data}
for template in self:
            template.task_count = sum(
                mapped.get(variant.id, 0) for variant in template.product_variant_ids
            )

Back to entity