From 242a9e9b05c682c24f8e06c458900731fab84e1f Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 7 Jul 2011 15:26:14 +0200 Subject: [PATCH] [IMP] tools: added a function to get and sort by field bzr revid: qdp-launchpad@openerp.com-20110707132614-c6letgrkz4d6vm0i --- openerp/tools/misc.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index dc66142fc4a..96e85413bff 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -1387,6 +1387,22 @@ def upload_data(email, data, type='SURVEY'): a.start() return True +def get_and_sort_by_field(cr, uid, obj, ids, field, context=None): + """ + This function reads a field on several ids and build a dictionary {KEY:VALUE} with: + KEY: field value + VALUE: all the ids of obj that share the same value for that field + """ + value_fields = obj.read(cr, uid, ids, [field],context=context) + res = {} + for item in value_fields: + key = item[field] + if isinstance(key,tuple): + key = key[0] + if not key in set_field: + res[key] = [] + res[key].append(item['id']) + return res # port of python 2.6's attrgetter with support for dotted notation def resolve_attr(obj, attr):