From 36c78e3e3ac1ddad024eb4324daf2bd1da80404c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 15 Oct 2020 13:40:21 +0000 Subject: [PATCH] [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 --- addons/crm/wizard/crm_lead_to_opportunity_mass.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity_mass.py b/addons/crm/wizard/crm_lead_to_opportunity_mass.py index 0dcc796e5f3..9deb29293e3 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity_mass.py +++ b/addons/crm/wizard/crm_lead_to_opportunity_mass.py @@ -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):