diff --git a/trytond/osv/fields.py b/trytond/osv/fields.py index 4f153efd0d..00f2bb4dbc 100644 --- a/trytond/osv/fields.py +++ b/trytond/osv/fields.py @@ -27,6 +27,7 @@ import psycopg2 import warnings import __builtin__ import sha +import inspect def _symbol_f(symb): if symb is None or symb == False: @@ -628,8 +629,23 @@ class Function(Column): def get(self, cursor, obj, ids, name, user=None, offset=0, context=None, values=None): - return getattr(obj, self._fnct)(cursor, user, ids, name, self._arg, - context=context) + if isinstance(name, list): + names = name + # Test is the function works with a list of names + if 'names' in inspect.getargspec(getattr(obj, self._fnct))[0]: + return getattr(obj, self._fnct)(cursor, user, ids, names, + self._arg, context=context) + res = {} + for name in names: + res[name] = getattr(obj, self._fnct)(cursor, user, ids, name, + self._arg, context=context) + return res + else: + # Test is the function works with a list of names + if 'names' in inspect.getargspec(getattr(obj, self._fnct))[0]: + name = [name] + return getattr(obj, self._fnct)(cursor, user, ids, name, self._arg, + context=context) def set(self, cursor, obj, obj_id, name, value, user=None, context=None): if self._fnct_inv: diff --git a/trytond/osv/orm.py b/trytond/osv/orm.py index 13fb106942..1acf7b8ed4 100644 --- a/trytond/osv/orm.py +++ b/trytond/osv/orm.py @@ -1035,12 +1035,26 @@ class ORM(object): # whose name is in load is False fields_post = [x for x in fields_names if x in self._columns \ and not getattr(self._columns[x], load)] + func_fields = {} for field in fields_post: + if isinstance(self._columns[field], fields.Function): + key = (self._columns[field]._fnct, self._columns[field]._arg) + func_fields.setdefault(key, []) + func_fields[key].append(field) + continue # get the value of that field for all records/ids res2 = self._columns[field].get(cursor, self, ids, field, user, context=context, values=res) for record in res: record[field] = res2[record['id']] + for i in func_fields: + field_list = func_fields[i] + field = field_list[0] + res2 = self._columns[field].get(cursor, self, ids, field_list, user, + context=context, values=res) + for field in res2: + for record in res: + record[field] = res2[field][record['id']] return res def _validate(self, cursor, user, ids, context=None):