[IMP] crm : change return values of merge_opportunity method
Since new API works with record, convert the return values from ids into recordset.
This commit is contained in:
@@ -599,7 +599,6 @@ class Lead(FormatAddress, models.Model):
|
||||
self._merge_opportunity_history(opportunities)
|
||||
self._merge_opportunity_attachments(opportunities)
|
||||
|
||||
#TODO JEM : make it return record
|
||||
@api.multi
|
||||
def merge_opportunity(self, user_id=False, team_id=False):
|
||||
""" Merge opportunities in one. Different cases of merge:
|
||||
@@ -609,7 +608,7 @@ class Lead(FormatAddress, models.Model):
|
||||
updated with values from other opportunities to merge.
|
||||
:param user_id : the id of the saleperson. If not given, will be determined by `_merge_data`.
|
||||
:param team : the id of the sales team. If not given, will be determined by `_merge_data`.
|
||||
:return int id: id of the resulting lead/opportunity
|
||||
:return crm.lead record resulting of th merge
|
||||
"""
|
||||
if len(self.ids) <= 1:
|
||||
raise UserError(_('Please select more than one element (lead or opportunity) from the list view.'))
|
||||
@@ -658,7 +657,7 @@ class Lead(FormatAddress, models.Model):
|
||||
# we use the SUPERUSER to avoid access rights issues because as the user had the rights to see the records it should be safe to do so
|
||||
opportunities_tail.sudo().unlink()
|
||||
|
||||
return opportunities_head.id
|
||||
return opportunities_head
|
||||
|
||||
@api.multi
|
||||
def get_duplicated_leads(self, partner_id, include_lost=False):
|
||||
|
||||
@@ -118,7 +118,6 @@ class Lead2OpportunityPartner(models.TransientModel):
|
||||
"""
|
||||
self.ensure_one()
|
||||
Lead = self.env['crm.lead']
|
||||
|
||||
opp_ids = self.opportunity_ids.ids
|
||||
values = {
|
||||
'team_id': self.team_id.id,
|
||||
@@ -128,20 +127,20 @@ class Lead2OpportunityPartner(models.TransientModel):
|
||||
values['partner_id'] = self.partner_id.id
|
||||
|
||||
if self.name == 'merge':
|
||||
lead_id = self.env['crm.lead'].browse(opp_ids).merge_opportunity()
|
||||
lead_ids = [lead_id]
|
||||
lead_data = Lead.browse(lead_id).read(['type', 'user_id'])[0]
|
||||
lead = self.env['crm.lead'].browse(opp_ids).merge_opportunity()
|
||||
lead_ids = [lead.id]
|
||||
lead_data = lead.read(['type', 'user_id'])[0]
|
||||
if lead_data['type'] == "lead":
|
||||
values.update({'lead_ids': lead_ids, 'user_ids': [self.user_id.id]})
|
||||
self.with_context(active_ids=lead_ids)._convert_opportunity(values)
|
||||
elif not self._context.get('no_force_assignation') or not lead_data['user_id']:
|
||||
values.update({'user_id': self.user_id.id})
|
||||
Lead.browse(lead_id).write(values)
|
||||
lead.write(values)
|
||||
else:
|
||||
lead_ids = self._context.get('active_ids', [])
|
||||
values.update({'lead_ids': lead_ids, 'user_ids': [self.user_id.id]})
|
||||
self._convert_opportunity(values)
|
||||
for lead in Lead.browse(lead_ids):
|
||||
for lead in self.env['crm.lead'].browse(lead_ids):
|
||||
if lead.partner_id and lead.partner_id.user_id != lead.user_id:
|
||||
self.env['res.partner'].browse(lead.partner_id.id).write({'user_id': lead.user_id.id})
|
||||
|
||||
@@ -240,9 +239,9 @@ class Lead2OpportunityMassConvert(models.TransientModel):
|
||||
lead = self.env['crm.lead'].browse(lead_id)
|
||||
duplicated_leads = self._get_duplicated_leads(lead.partner_id.id, lead.partner_id.email if lead.partner_id else lead.email_from)
|
||||
if len(duplicated_leads) > 1:
|
||||
lead_id = duplicated_leads.merge_opportunity()
|
||||
lead = duplicated_leads.merge_opportunity()
|
||||
merged_lead_ids.extend(duplicated_leads.ids)
|
||||
remaining_lead_ids.append(lead_id)
|
||||
remaining_lead_ids.append(lead.id)
|
||||
active_ids = set(self._context.get('active_ids', []))
|
||||
active_ids = active_ids.difference(merged_lead_ids)
|
||||
active_ids = active_ids.union(remaining_lead_ids)
|
||||
|
||||
@@ -39,10 +39,9 @@ class MergeOpportunity(models.TransientModel):
|
||||
@api.multi
|
||||
def action_merge(self):
|
||||
self.ensure_one()
|
||||
merge_opportunity_id = self.opportunity_ids.merge_opportunity(self.user_id.id, self.team_id.id)
|
||||
merge_opportunity = self.opportunity_ids.merge_opportunity(self.user_id.id, self.team_id.id)
|
||||
|
||||
# The newly created lead might be a lead or an opp: redirect toward the right view
|
||||
merge_opportunity = self.env['crm.lead'].browse(merge_opportunity_id)
|
||||
if merge_opportunity.type == 'opportunity':
|
||||
return merge_opportunity.redirect_opportunity_view()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user