'Prepare lead/opp data into a dictionary for merging. Different types
of fields are processed in different ways:
- text: all the values are concatenated
- m2m and o2m: those fields aren\'t processed
- m2o: the first not null value prevails (the other are dropped)
- any other type of field: same as m2o
:param fields: list of fields to process
:return dict data: contains the merged values of the new opportunity'

@api.multi
def _merge_data(self, fields):

    def _get_first_not_null(attr, opportunities):
        for opp in opportunities:
            val = opp[attr]
            if val:
                return val
        return False
    def _get_first_not_null_id(attr, opportunities):
        res = _get_first_not_null(attr, opportunities)
        return (res.id if res else False)
    def _concat_all(attr, opportunities):
        return '\n\n'.join(filter(None, (opp[attr] for opp in opportunities)))
    data = {}
    for field_name in fields:
        field = self._fields.get(field_name)
        if (field is None):
            continue
        if (field.type in ('many2many', 'one2many')):
            continue
        elif (field.type == 'many2one'):
            data[field_name] = _get_first_not_null_id(field_name, self)
        elif (field.type == 'text'):
            data[field_name] = _concat_all(field_name, self)
        else:
            data[field_name] = _get_first_not_null(field_name, self)
    data['type'] = self._merge_get_result_type()
    return data
