[FIX] merge of leads/opps with attachments

bzr revid: qdp-launchpad@openerp.com-20130220140936-qy04t7hjebsc9tgg
This commit is contained in:
Quentin (OpenERP) 2013-02-20 15:09:36 +01:00
commit 8711625764
1 changed files with 12 additions and 14 deletions

View File

@ -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):