diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 294adc863b5..6abce8921cf 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -587,27 +587,25 @@ class crm_lead(base_stage, format_address, osv.osv): return True def _merge_opportunity_attachments(self, cr, uid, opportunity_id, opportunities, context=None): - attachment = self.pool.get('ir.attachment') + attach_obj = self.pool.get('ir.attachment') # return attachments of opportunity def _get_attachments(opportunity_id): - attachment_ids = attachment.search(cr, uid, [('res_model', '=', self._name), ('res_id', '=', opportunity_id)], context=context) - return attachment.browse(cr, uid, attachment_ids, context=context) + attachment_ids = attach_obj.search(cr, uid, [('res_model', '=', self._name), ('res_id', '=', opportunity_id)], context=context) + return attach_obj.browse(cr, uid, attachment_ids, context=context) - count = 1 first_attachments = _get_attachments(opportunity_id) + #counter of all attachments to move. Used to make sure the name is different for all attachments + count = 1 for opportunity in opportunities: attachments = _get_attachments(opportunity.id) - for first in first_attachments: - for attachment in attachments: - if attachment.name == first.name: - values = dict( - name = "%s (%s)" % (attachment.name, count,), - res_id = opportunity_id, - ) - attachment.write(values) - count+=1 - + for attachment in attachments: + values = {'res_id': opportunity_id,} + for attachment_in_first in first_attachments: + if attachment.name == attachment_in_first.name: + name = "%s (%s)" % (attachment.name, count,), + count+=1 + attachment.write(values) return True def merge_opportunity(self, cr, uid, ids, context=None):