[IMP] tools: added a function to get and sort by field

bzr revid: qdp-launchpad@openerp.com-20110707132614-c6letgrkz4d6vm0i
This commit is contained in:
Quentin (OpenERP) 2011-07-07 15:26:14 +02:00
parent f51a5e1498
commit 242a9e9b05
1 changed files with 16 additions and 0 deletions

View File

@ -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):