Merge lp:~openerp-dev/openobject-server/7.0-func-field-postprocess-batch-chs into lp:openobject-server/7.0

Proposed by Christophe Simonis (OpenERP)
Status: Merged
Merge reported by: Christophe Simonis (OpenERP)
Merged at revision: not available
Proposed branch: lp:~openerp-dev/openobject-server/7.0-func-field-postprocess-batch-chs
Merge into: lp:openobject-server/7.0
Diff against target: 98 lines (+52/-25)
1 file modified
openerp/osv/fields.py (+52/-25)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-func-field-postprocess-batch-chs
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+208224@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

merged in trunk (no IMP in stable)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/osv/fields.py'
--- openerp/osv/fields.py 2014-02-13 10:08:36 +0000
+++ openerp/osv/fields.py 2014-02-25 20:39:27 +0000
@@ -1111,42 +1111,69 @@
1111 return self._fnct_search(obj, cr, uid, obj, name, args, context=context)1111 return self._fnct_search(obj, cr, uid, obj, name, args, context=context)
11121112
1113 def postprocess(self, cr, uid, obj, field, value=None, context=None):1113 def postprocess(self, cr, uid, obj, field, value=None, context=None):
1114 return self._postprocess_batch(cr, uid, obj, field, {0: value}, context=context)[0]
1115
1116 def _postprocess_batch(self, cr, uid, obj, field, values, context=None):
1117 if not values:
1118 return values
1119
1114 if context is None:1120 if context is None:
1115 context = {}1121 context = {}
1116 result = value1122
1117 field_type = obj._columns[field]._type1123 field_type = obj._columns[field]._type
1118 if field_type == "many2one":1124 new_values = dict(values)
1119 # make the result a tuple if it is not already one1125
1120 if isinstance(value, (int,long)) and hasattr(obj._columns[field], 'relation'):1126 if field_type == "integer":
1121 obj_model = obj.pool.get(obj._columns[field].relation)
1122 dict_names = dict(obj_model.name_get(cr, SUPERUSER_ID, [value], context))
1123 result = (value, dict_names[value])
1124
1125 if field_type == 'binary':
1126 if context.get('bin_size'):
1127 # client requests only the size of binary fields
1128 result = get_nice_size(value)
1129 elif not context.get('bin_raw'):
1130 result = sanitize_binary_value(value)
1131
1132 if field_type == "integer" and value > xmlrpclib.MAXINT:
1133 # integer/long values greater than 2^31-1 are not supported1127 # integer/long values greater than 2^31-1 are not supported
1134 # in pure XMLRPC, so we have to pass them as floats :-(1128 # in pure XMLRPC, so we have to pass them as floats :-(
1135 # This is not needed for stored fields and non-functional integer1129 # This is not needed for stored fields and non-functional integer
1136 # fields, as their values are constrained by the database backend1130 # fields, as their values are constrained by the database backend
1137 # to the same 32bits signed int limit.1131 # to the same 32bits signed int limit.
1138 result = __builtin__.float(value)1132 for rid, value in values.iteritems():
1139 return result1133 if value and value > xmlrpclib.MAXINT:
1134 new_values[rid] = __builtin__.float(value)
1135
1136 elif field_type == 'binary':
1137 if context.get('bin_size'):
1138 # client requests only the size of binary fields
1139 for rid, value in values.iteritems():
1140 if value:
1141 new_values[rid] = get_nice_size(value)
1142 elif not context.get('bin_raw'):
1143 for rid, value in values.iteritems():
1144 if value:
1145 new_values[rid] = sanitize_binary_value(value)
1146
1147 elif field_type == "many2one" and hasattr(obj._columns[field], 'relation'):
1148 # make the result a tuple if it is not already one
1149 if all(isinstance(value, (int, long)) for value in values.values() if value):
1150 obj_model = obj.pool[obj._columns[field].relation]
1151 ids = [i for i in values.values() if i]
1152 dict_names = dict(obj_model.name_get(cr, SUPERUSER_ID, ids, context))
1153 for rid, value in values.iteritems():
1154 if value:
1155 new_values[rid] = (value, dict_names[value])
1156
1157 return new_values
11401158
1141 def get(self, cr, obj, ids, name, uid=False, context=None, values=None):1159 def get(self, cr, obj, ids, name, uid=False, context=None, values=None):
1142 result = self._fnct(obj, cr, uid, ids, name, self._arg, context)1160 result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
1143 for id in ids:1161 if self._multi:
1144 if self._multi and id in result:1162 swap = {}
1145 for field, value in result[id].iteritems():1163 for rid, values in result.iteritems():
1146 if value:1164 for f, v in values.iteritems():
1147 result[id][field] = self.postprocess(cr, uid, obj, field, value, context)1165 if f not in name:
1148 elif result.get(id):1166 continue
1149 result[id] = self.postprocess(cr, uid, obj, name, result[id], context)1167 swap.setdefault(f, {})[rid] = v
1168
1169 for field, values in swap.iteritems():
1170 new_values = self._postprocess_batch(cr, uid, obj, field, values, context)
1171 for rid, value in new_values.iteritems():
1172 result[rid][field] = value
1173
1174 else:
1175 result = self._postprocess_batch(cr, uid, obj, name, result, context)
1176
1150 return result1177 return result
11511178
1152 def set(self, cr, obj, id, name, value, user=None, context=None):1179 def set(self, cr, obj, id, name, value, user=None, context=None):