'Update all foreign key from the src_partner to dst_partner. All many2one fields will be updated.
:param src_partners : merge source res.partner recordset (does not include destination one)
:param dst_partner : record of destination res.partner'

@api.model
def _update_foreign_keys(self, src_partners, dst_partner):

    _logger.debug('_update_foreign_keys    for    dst_partner:    %s    for    src_partners:    %s', dst_partner.id, str(src_partners.ids))
    Partner = self.env['res.partner']
    relations = self._get_fk_on('res_partner')
    for (table, column) in relations:
        if ('base_partner_merge_' in table):
            continue
        query = ("SELECT    column_name    FROM    information_schema.columns    WHERE    table_name    LIKE    '%s'" % table)
        self._cr.execute(query, ())
        columns = []
        for data in self._cr.fetchall():
            if (data[0] != column):
                columns.append(data[0])
        query_dic = {'table': table, 'column': column, 'value': columns[0]}
        if (len(columns) <= 1):
            query = ('\n                                                                                UPDATE    "%(table)s"    as    ___tu\n                                                                                SET    %(column)s    =    %%s\n                                                                                WHERE\n                                                                                                %(column)s    =    %%s    AND\n                                                                                                NOT    EXISTS    (\n                                                                                                                SELECT    1\n                                                                                                                FROM    "%(table)s"    as    ___tw\n                                                                                                                WHERE\n                                                                                                                                %(column)s    =    %%s    AND\n                                                                                                                                ___tu.%(value)s    =    ___tw.%(value)s\n                                                                                                )' % query_dic)
            for partner in src_partners:
                self._cr.execute(query, (dst_partner.id, partner.id, dst_partner.id))
        else:
            try:
                with mute_logger('odoo.sql_db'):
                    with self._cr.savepoint():
                        query = ('UPDATE    "%(table)s"    SET    %(column)s    =    %%s    WHERE    %(column)s    IN    %%s' % query_dic)
                        self._cr.execute(query, (dst_partner.id, tuple(src_partners.ids)))
                        if ((column == Partner._parent_name) and (table == 'res_partner')):
                            query = '\n                                                                                                                                WITH    RECURSIVE    cycle(id,    parent_id)    AS    (\n                                                                                                                                                                SELECT    id,    parent_id    FROM    res_partner\n                                                                                                                                                UNION\n                                                                                                                                                                SELECT        cycle.id,    res_partner.parent_id\n                                                                                                                                                                FROM                res_partner,    cycle\n                                                                                                                                                                WHERE            res_partner.id    =    cycle.parent_id    AND\n                                                                                                                                                                                                cycle.id    !=    cycle.parent_id\n                                                                                                                                )\n                                                                                                                                SELECT    id    FROM    cycle    WHERE    id    =    parent_id    AND    id    =    %s\n                                                                                                                '
                            self._cr.execute(query, (dst_partner.id,))
            except psycopg2.Error:
                query = ('DELETE    FROM    %(table)s    WHERE    %(column)s    IN    %%s' % query_dic)
                self._cr.execute(query, (tuple(src_partners.ids),))
