[FIX] website: make filter_duplicate work
itertools' groupby function expects the iterable to be sorted as hinted to in the documentation: "Generally, the iterable needs to already be sorted on the same key function." When running groupby on an unsorted iterable non-adjacent duplicates will remain: >>> from itertools import groupby >>> [e[0] for e in groupby([1, 2, 1])] [1, 2, 1] Because of this filter_duplicate would occassionally return duplicates. To resolve this sort on the key field. Afterwards sort the result on the usual inherit order: (priority, id).
This commit is contained in:
committed by
Jeremy Kersten
parent
0e45dfc591
commit
5ff87e8039
@@ -55,9 +55,9 @@ class View(models.Model):
|
||||
def filter_duplicate(self):
|
||||
""" Filter current recordset only keeping the most suitable view per distinct key """
|
||||
filtered = self.env['ir.ui.view']
|
||||
for dummy, group in groupby(self, key=lambda record: record.key):
|
||||
for dummy, group in groupby(self.sorted('key'), key=lambda record: record.key):
|
||||
filtered += sorted(group, key=lambda record: record._sort_suitability_key())[0]
|
||||
return filtered
|
||||
return filtered.sorted(key=lambda view: (view.priority, view.id))
|
||||
|
||||
@api.model
|
||||
def _view_obj(self, view_id):
|
||||
|
||||
Reference in New Issue
Block a user