[IMP] fields.function: don't wrap int values unless really needed

There was no need to wrap/cast int values for values less
than 2^31-1, which the highest XML-RPC int value.
Also, instead of wrapping them in strings, we can use
float values, which are 64bits based in the XMLRPC standard,
and closer to the real value (for comparisons, etc.).
Added note for integer_big, as a reminder of this possible
issue.

bzr revid: qdp-launchpad@openerp.com-20110818120550-ulvffm6ka9f3c5ym
This commit is contained in:
Olivier Dony 2011-08-18 14:05:50 +02:00 committed by Quentin (OpenERP)
parent c88797cfe6
commit 8ac7724a67
1 changed files with 15 additions and 2 deletions

View File

@ -145,6 +145,14 @@ class integer(_column):
_symbol_get = lambda self,x: x or 0
class integer_big(_column):
"""Experimental 64 bit integer column type, currently unused.
TODO: this field should work fine for values up
to 32 bits, but greater values will not fit
in the XML-RPC int type, so a specific
get() method is needed to pass them as floats,
like what we do for integer functional fields.
"""
_type = 'integer_big'
# do not reference the _symbol_* of integer class, as that would possibly
# unbind the lambda functions
@ -1026,8 +1034,13 @@ class function(_column):
else:
result = sanitize_binary_value(value)
if field_type == "integer":
result = tools.ustr(value)
if field_type in ("integer","integer_big") and value > xmlrpclib.MAXINT:
# integer/long values greater than 2^31-1 are not supported
# in pure XMLRPC, so we have to pass them as floats :-(
# This is not needed for stored fields and non-functional integer
# fields, as their values are constrained by the database backend
# to the same 32bits signed int limit.
result = float(value)
return result
def get(self, cr, obj, ids, name, uid=False, context=None, values=None):