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

Module: CRM

Entity: res.partner

Compute Method: _compute_opportunity_count

Inputs Method Outputs
  • id
  • parent_id
self.opportunity_count = 0
if not self.env.user.has_group('sales_team.group_sale_salesman'):
            return
opportunity_data = self.env['crm.lead'].with_context(active_test=False)._read_group(
            domain=self._get_contact_opportunities_domain(),
            groupby=['partner_id'], aggregates=['__count']
        )
current_pids = set(self._ids)
for partner, count in opportunity_data:
            while partner:
                if partner.id in current_pids:
                    partner.opportunity_count += count
                partner = partner.parent_id

Back to entity