[FIX] crm: keep order of lead ids when mass converting

Purpose of this commit is to avoid the use of sets in convert wizard. This set
is used to compute ids of leads to merge and to convert. Using a set make order
impossible to predict. Using lists allows to have reproducible tests notably.

Spotted when working on task ID-2086889
This commit is contained in:
Thibault Delavallée
2020-12-01 11:17:34 +00:00
parent 8bde0c810c
commit 36c78e3e3a
@@ -81,6 +81,8 @@ class Lead2OpportunityMassConvert(models.TransientModel):
def action_mass_convert(self):
self.ensure_one()
if self.name == 'convert' and self.deduplicate:
# TDE CLEANME: still using active_ids from context
active_ids = self._context.get('active_ids', [])
merged_lead_ids = set()
remaining_lead_ids = set()
for lead in self.lead_tomerge_ids:
@@ -94,10 +96,11 @@ class Lead2OpportunityMassConvert(models.TransientModel):
lead = duplicated_leads.merge_opportunity()
merged_lead_ids.update(duplicated_leads.ids)
remaining_lead_ids.add(lead.id)
active_ids = set(self._context.get('active_ids', {}))
active_ids = (active_ids - merged_lead_ids) | remaining_lead_ids
# rebuild list of lead IDS to convert, following given order
final_ids = [lead_id for lead_id in active_ids if lead_id not in merged_lead_ids]
final_ids += [lead_id for lead_id in remaining_lead_ids if lead_id not in final_ids]
self = self.with_context(active_ids=list(active_ids)) # only update active_ids when there are set
self = self.with_context(active_ids=final_ids) # only update active_ids when there are set
return self.action_apply()
def _convert_handle_partner(self, lead, action, partner_id):