From 36e5b6e88e24877b34a99be7fea1d92c1b85aa6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 20 Dec 2012 15:18:42 +0100 Subject: [PATCH] [FIX] _search not uniquifies the results, because when using _auto_join we could have duplicates in the 'left part' of the result, i.e. a lead with several unread messages. This is done using a custom method instead of a set, because sets are unordered. bzr revid: tde@openerp.com-20121220141842-or3bigz11qkb13qn --- openerp/addons/base/ir/ir_needaction.py | 2 +- openerp/osv/orm.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/ir/ir_needaction.py b/openerp/addons/base/ir/ir_needaction.py index 1f51f4667e6..745546ad0f2 100644 --- a/openerp/addons/base/ir/ir_needaction.py +++ b/openerp/addons/base/ir/ir_needaction.py @@ -61,5 +61,5 @@ class ir_needaction_mixin(osv.AbstractModel): dom = self._needaction_domain_get(cr, uid, context=context) if not dom: return 0 - res = self.search(cr, uid, (domain or []) + dom, limit=100, order='id DESC', context=context) + res = self.search(cr, uid, (domain or []) + dom, limit=1000, order='id DESC', context=context) return len(res) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 92eb8dad776..840758f753d 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -4857,7 +4857,15 @@ class BaseModel(object): return res[0][0] cr.execute('SELECT "%s".id FROM ' % self._table + from_clause + where_str + order_by + limit_str + offset_str, where_clause_params) res = cr.fetchall() - return [x[0] for x in res] + + # TDE note: with auto_join, we could have several lines about the same result + # i.e. a lead with several unread messages; we uniquify the result using + # a fast way to do it while preserving order (http://www.peterbe.com/plog/uniqifiers-benchmark) + def _uniquify_list(seq): + seen = set() + return [x for x in seq if x not in seen and not seen.add(x)] + + return _uniquify_list([x[0] for x in res]) # returns the different values ever entered for one field # this is used, for example, in the client when the user hits enter on