From 5b028251943a36308c71e07dd7d7900a3447523a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Jun 2016 14:03:54 +0200 Subject: [PATCH] [FIX] crm : name_get use In the new API, ``name_get`` doesn't normally lose sort information anymore: the result of ``search`` (or ``browse(_search)``) is correctly ordered and ``name_get`` sequentially resolves record names. Thus the post-facto re-ordering mess should be unnecessary, ``records.name_get()`` will be ordered as ``records`` is. --- addons/crm/models/crm_lead.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 3502edfc262..ae049195238 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -161,23 +161,19 @@ class Lead(FormatAddress, models.Model): # - ('id', 'in', 'ids'): add columns that should be present # - OR ('fold', '=', False): add default columns that are not folded # - OR ('team_ids', '=', team_id), ('fold', '=', False) if team_id: add team columns that are not folded - team_id = self._context.get('default_team_id', False) + team_id = self._context.get('default_team_id') if team_id: search_domain = ['|', ('id', 'in', self.ids), '|', ('team_id', '=', False), ('team_id', '=', team_id)] else: search_domain = ['|', ('id', 'in', self.ids), ('team_id', '=', False)] - # perform search - stage_ids = Stage._search(search_domain, order=order, access_rights_uid=access_rights_uid) - stages = Stage.browse(stage_ids) - result = stages.name_get() - # restore order of the search - order_mapping = {item[0]: stage_ids.index(item[0]) for item in result} # match stage_id with its index - result.sort(key=lambda item: order_mapping.get(item[0])) - fold = {} - for stage in stages: - fold[stage.id] = stage.fold or False - return result, fold + # perform search + stages = Stage.browse(Stage._search(search_domain, order=order, access_rights_uid=access_rights_uid)) + fold = { + stage.id: stage.fold or False + for stage in stages + } + return stages.name_get(), fold _group_by_full = { 'stage_id': _read_group_stage_ids