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

Module: Partner Email Duplicate Warn

Entity: res.partner

Compute Method: _compute_same_email_partner_ids

Inputs Method Outputs
  • email
  • company_id
  • company_id.id
for partner in self:
            same_email_partner_ids = []
            inaccessible_count = 0
            if partner.email and partner.email.strip():
                partner_email = partner.email.strip().lower()
                domain = [("email", "=ilike", "%" + partner_email + "%")]
                if partner.company_id:
                    domain += [
                        "|",
                        ("company_id", "=", False),
                        ("company_id", "=", partner.company_id.id),
                    ]
                partner_id = partner._origin.id
                if partner_id:
                    domain += [
                        ("id", "!=", partner_id),
                        "!",
                        ("id", "child_of", partner_id),
                        "!",
                        ("id", "parent_of", partner_id),
                    ]
                search_partners = self.with_context(active_test=False).search(domain)
                matches = search_partners.filtered(
                    lambda p, email=partner_email: p.email
                    and p.email.strip().lower() == email
                )
                # This field is computed as superuser (compute_sudo), so the
                # match set may include partners the acting user cannot read.
                # Only expose the readable ones as links; rendering the others
                # would raise an AccessError when the web client fetches their
                # display_name. The rest are merely counted so the banner can
                # warn about them without disclosing their identity.
                readable = matches.with_env(self.env(su=False))._filtered_access("read")
                same_email_partner_ids = readable.ids
                inaccessible_count = len(matches) - len(readable)
            partner.same_email_partner_ids = same_email_partner_ids or False
            partner.same_email_inaccessible_count = inaccessible_count

Back to entity