Merge lp:~openerp-dev/openobject-server/6.0-opw-578249-rha into lp:openobject-server/6.0

Proposed by Rifakat Husen (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-578249-rha
Merge into: lp:openobject-server/6.0
Diff against target: 78 lines (+35/-27)
1 file modified
bin/osv/fields.py (+35/-27)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-578249-rha
Reviewer Review Type Date Requested Status
Naresh(OpenERP) Pending
Olivier Dony (Odoo) Pending
Review via email: mp+121826@code.launchpad.net

Description of the change

Hello,

Fixed issue for fields.function with multi argument, it is mixing up the type when
we use multi argument for different type int & m2o.

When int field comes in higher execution order in list of fields in that case it gets
its value based on int type and convert the value into string which may cause problem.
This fix converted int value to float instead of string while value is greater than xmlrpc limit.

This is a partial backport from stable 6.1
Thanks for your review.

Sincerely,
Rifakat Haradwala

To post a comment you must log in.
Revision history for this message
Rifakat Husen (OpenERP) (rha-openerp) wrote :

Unmerged revisions

3636. By Olivier Dony (Odoo)

fields.py: fields.function with multi argument mixing up type for m2o and integer which applies wrong value for other field,
backported from 6.1
converted int value to float instead of string while value is greater than xmlrpc limit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/osv/fields.py'
2--- bin/osv/fields.py 2012-03-14 12:49:12 +0000
3+++ bin/osv/fields.py 2012-08-29 10:53:52 +0000
4@@ -803,6 +803,34 @@
5 return []
6 return self._fnct_search(obj, cr, uid, obj, name, args, context=context)
7
8+ def postprocess(self, cr, uid, obj, field, value=None, context=None):
9+ if context is None:
10+ context = {}
11+ result = value
12+ field_type = obj._columns[field]._type
13+ if field_type == "many2one":
14+ # make the result a tuple if it is not already one
15+ if isinstance(value, (int,long)) and hasattr(obj._columns[field], 'relation'):
16+ obj_model = obj.pool.get(obj._columns[field].relation)
17+ dict_names = dict(obj_model.name_get(cr, uid, [value], context))
18+ result = (value, dict_names[value])
19+
20+ if field_type == 'binary':
21+ if context.get('bin_size'):
22+ # client requests only the size of binary fields
23+ result = get_nice_size((None,value))[1]
24+ else:
25+ result = sanitize_binary_value((None,value))[1]
26+
27+ if field_type == "integer" and value > xmlrpclib.MAXINT:
28+ # integer/long values greater than 2^31-1 are not supported
29+ # in pure XMLRPC, so we have to pass them as floats :-(
30+ # This is not needed for stored fields and non-functional integer
31+ # fields, as their values are constrained by the database backend
32+ # to the same 32bits signed int limit.
33+ result = __builtin__.float(value)
34+ return result
35+
36 def get(self, cr, obj, ids, name, user=None, context=None, values=None):
37 if context is None:
38 context = {}
39@@ -813,33 +841,13 @@
40 res = self._fnct(obj, cr, user, ids, name, self._arg, context)
41 else:
42 res = self._fnct(cr, obj._table, ids, name, self._arg, context)
43-
44- if self._type == "many2one" :
45- # Filtering only integer/long values if passed
46- res_ids = [x for x in res.values() if x and isinstance(x, (int,long))]
47-
48- if res_ids:
49- obj_model = obj.pool.get(self._obj)
50- dict_names = dict(obj_model.name_get(cr, user, res_ids, context))
51- for r in res.keys():
52- if res[r] and res[r] in dict_names:
53- res[r] = (res[r], dict_names[res[r]])
54-
55- if self._type == 'binary':
56- if context.get('bin_size', False):
57- # client requests only the size of binary fields
58- res = dict(map(get_nice_size, res.items()))
59- else:
60- res = dict(map(sanitize_binary_value, res.items()))
61-
62- if self._type == "integer":
63- for r in res.keys():
64- # Converting value into string so that it does not affect XML-RPC Limits
65- if isinstance(res[r],dict): # To treat integer values with _multi attribute
66- for record in res[r].keys():
67- res[r][record] = str(res[r][record])
68- else:
69- res[r] = str(res[r])
70+ for id in ids:
71+ if self._multi and id in res:
72+ for field, value in res[id].iteritems():
73+ if value:
74+ res[id][field] = self.postprocess(cr, user, obj, field, value, context)
75+ elif res.get(id):
76+ res[id] = self.postprocess(cr, user, obj, name, res[id], context)
77 return res
78 get_memory = get
79