Juan Ramon Alfaro Martinez
unread,Aug 18, 2017, 3:00:05 AM8/18/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to tryton-dev
Hello.
I have need to campare a Date in pyson and I have modified pyson.py in trytond to support it, if someone wants to push upstream this is the patch.
--- pyson.py.old 2017-08-18 07:53:10.705049046 +0200
+++ pyson.py 2017-08-18 07:54:47.925945516 +0200
@@ -24,7 +24,13 @@
return reduced_type(func(*args, **kwargs))
return wrapper
-
+def date_to_float(statement1):
+ if isinstance(statement1, datetime.datetime):
+ statement1=(statement1-datetime.datetime(1970,1,1)).total_seconds()
+ if isinstance(statement1, datetime.date):
+ statement1=(statement1-datetime.date(1970,1,1)).total_seconds()
+ return statement1
+
class PYSON(object):
def pyson(self):
@@ -313,7 +319,7 @@
super(Greater, self).__init__()
for i in (statement1, statement2):
if isinstance(i, PYSON):
- assert i.types().issubset(set([int, long, float])), \
+ assert i.types().issubset(set([int, long, float, datetime.date, datetime.datetime ])), \
'statement must be an integer or a float'
else:
assert isinstance(i, (int, long, float)), \
@@ -346,7 +352,7 @@
for i in ('s1', 's2'):
if not isinstance(dct[i], (int, long, float)):
dct = dct.copy()
- dct[i] = float(dct[i])
+ dct[i] = float(date_to_float(dct[i]))
return dct
@staticmethod
@@ -711,4 +717,3 @@
'Len': Len,
'Id': Id,
}
-