'Update all reference fields from the src_partner to dst_partner.
: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_reference_fields(self, src_partners, dst_partner):

    _logger.debug('_update_reference_fields    for    dst_partner:    %s    for    src_partners:    %r', dst_partner.id, src_partners.ids)
    def update_records(model, src, field_model='model', field_id='res_id'):
        Model = (self.env[model] if (model in self.env) else None)
        if (Model is None):
            return
        records = Model.sudo().search([(field_model, '=', 'res.partner'), (field_id, '=', src.id)])
        try:
            with mute_logger('odoo.sql_db'):
                with self._cr.savepoint():
                    return records.sudo().write({field_id: dst_partner.id})
        except psycopg2.Error:
            return records.sudo().unlink()
    update_records = functools.partial(update_records)
    for partner in src_partners:
        update_records('calendar', src=partner, field_model='model_id.model')
        update_records('ir.attachment', src=partner, field_model='res_model')
        update_records('mail.followers', src=partner, field_model='res_model')
        update_records('mail.message', src=partner)
        update_records('marketing.campaign.workitem', src=partner, field_model='object_id.model')
        update_records('ir.model.data', src=partner)
    records = self.env['ir.model.fields'].search([('ttype', '=', 'reference')])
    for record in records.sudo():
        try:
            Model = self.env[record.model]
            field = Model._fields[record.name]
        except KeyError:
            continue
        if (field.compute is not None):
            continue
        for partner in src_partners:
            records_ref = Model.sudo().search([(record.name, '=', ('res.partner,%d' % partner.id))])
            values = {record.name: ('res.partner,%d' % dst_partner.id)}
            records_ref.sudo().write(values)
