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

Module: Invoicing

Entity: res.partner.bank

Compute Method: _compute_duplicate_bank_partner_ids

Inputs Method Outputs
id2duplicates = dict(self.env.execute_query(SQL(
            """
                SELECT this.id,
                       ARRAY_AGG(other.partner_id)
                  FROM res_partner_bank this
             LEFT JOIN res_partner_bank other ON this.account_number = other.account_number
                                             AND this.id != other.id
                                             AND other.active = TRUE
                 WHERE this.id = ANY(%(ids)s)
                 AND other.partner_id IS NOT NULL
                   AND this.active = TRUE
                   AND (
                        ((this.company_id = other.company_id) OR (this.company_id IS NULL AND other.company_id IS NULL))
                        OR
                        other.company_id IS NULL
                        )
              GROUP BY this.id
            """,
            ids=self.ids,
        )))
for bank in self:
            duplicate_record = id2duplicates.get(bank._origin.id) or []
            duplicate_record = [x for x in duplicate_record if x]
            bank.duplicate_bank_partner_ids = self.env['res.partner'].browse(duplicate_record) if duplicate_record else False

Back to entity