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

Module: Recruitment

Entity: hr.candidate

Compute Method: _compute_similar_candidates_count

Inputs Method Outputs
  • id
"""
            The field similar_candidates_count is only used on the form view.
            Thus, using ORM rather then querying, should not make much
            difference in terms of performance, while being more readable and secure.
        """
if not any(self._ids):
            for candidate in self:
                domain = candidate._get_similar_candidates_domain()
                if domain:
                    candidate.similar_candidates_count = max(0, self.env["hr.candidate"].with_context(active_test=False).search_count(domain) - 1)
                else:
                    candidate.similar_candidates_count = 0
            return
self.flush_recordset(['email_normalized', 'partner_phone_sanitized'])
self.env.cr.execute("""
            SELECT
                id,
                (
                    SELECT COUNT(*)
                    FROM hr_candidate AS sub
                    WHERE c.id != sub.id
                     AND ((coalesce(c.email_normalized, '') <> '' AND sub.email_normalized = c.email_normalized)
                       OR (coalesce(c.partner_phone_sanitized, '') <> '' AND c.partner_phone_sanitized = sub.partner_phone_sanitized))
                      AND c.company_id = sub.company_id
                ) AS similar_candidates
            FROM hr_candidate AS c
            WHERE id IN %(ids)s
        """, {'ids': tuple(self._origin.ids)})
query_results = self.env.cr.dictfetchall()
mapped_data = {result['id']: result['similar_candidates'] for result in query_results}
for candidate in self:
            candidate.similar_candidates_count = mapped_data.get(candidate.id, 0)

Back to entity