Commit b87aef6c authored by Sebastien Robin's avatar Sebastien Robin

added support for float format, also updated test

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14749 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7445e621
......@@ -1785,6 +1785,22 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.failUnless(isinstance(uid, long))
self.assertEquals(organisation.uid, uid)
def test_55_FloatFormat(self, quiet=quiet, run=run_all_test):
if not run: return
if not quiet:
message = 'Float Format'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
org_a = self._makeOrganisation(title='org_a')
org_b = self._makeOrganisation(title='org_b')
sql_connection = self.getSQLConnection()
# Add a method in order to directly put values we want into
# the catalog.
catalog_kw = {'uid':{'query':'2 567.54',
'format':'1 234.12',
'type':'float'}}
sql_src = self.getCatalogTool()(src__=1,**catalog_kw)
self.failUnless('TRUNCATE(catalog.uid,2) = 2567.54' in sql_src)
if __name__ == '__main__':
framework()
......
......@@ -205,6 +205,9 @@ class QueryMixin:
value = value.strftime(format)
if isinstance(value, basestring):
value = "STR_TO_DATE('%s','%s')" % (value, format)
if type == 'float':
# Make sure there is no space in float values
value = value.replace(' ','')
else:
if hasattr(value, 'ISO'):
value = "'%s'" % value.ISO()
......@@ -222,13 +225,19 @@ class QueryMixin:
if format is not None and type is not None:
if type == 'date':
key = "STR_TO_DATE(DATE_FORMAT(%s,'%s'),'%s')" % (key, format, format)
if type == 'float':
float_format = format.replace(' ','')
if float_format.find('.') >= 0:
precision = len(float_format.split('.')[1])
key = "TRUNCATE(%s,%s)" % (key, precision)
return key
class Query(QueryMixin):
"""
This allow to define constraints on a sql column
format - %d/%m/%Y
format - type date : %d/%m/%Y
type float : 1 234.12
"""
def __init__(self, format=None, operator=None, range=None,
search_mode=None, table_alias_list=None, type=None, **kw):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment