Issue 4879

Title
Suport Date, DateTime and Decimal fields in Greater/Less Pyson statement
Priority
feature
Status
resolved
Nosy list
amon-ra, ced, edbo, guillemNaN, pokoli, resteve, reviewbot, roundup-bot
Assigned to
ced
Keywords
patch, review

Created on 2015-07-16.10:15:19 by guillemNaN, last changed 2 months ago by roundup-bot.

Files

File name Uploaded Type Details
pyson.diff amon-ra, 2017-08-18.10:34:25 text/plain view

Messages

New changeset e091583154ad by Cédric Krier in branch 'default':
Support PYSON comparison of date and datetime
https://hg.tryton.org/tryton-env/rev/e091583154ad
New changeset 080a43fdf5d2 by Cédric Krier in branch 'default':
Support PYSON comparison of date and datetime
https://hg.tryton.org/trytond/rev/080a43fdf5d2
New changeset 5ce1d6984748 by Cédric Krier in branch 'default':
Support PYSON comparison of date and datetime
https://hg.tryton.org/tryton/rev/5ce1d6984748
New changeset eb238bf04203 by Cédric Krier in branch 'default':
Support PYSON comparison of date and datetime
https://hg.tryton.org/sao/rev/eb238bf04203
New changeset 8e60d41aa412 by Cédric Krier in branch 'default':
Support PYSON comparison of date and datetime
https://hg.tryton.org/proteus/rev/8e60d41aa412
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2019-08-08.15:25:58
It is probably better to use momentjs comparison.
Author: [hidden] (edbo)
Date: 2019-08-08.15:04:32
Because Sao uses momentjs for dates and times, it is automatically converted into a UNIX timestamp when converting it to a number [1]. Do we want that or should we use the isBefore, isAfter etc from momentjs [2]?

[1] = http://hg.tryton.org/sao/file/tip/src/pyson.js#l421
[2] = https://momentjs.com/docs/#/query/
Author: [hidden] (edbo)
Date: 2019-08-08.15:00:09
>> And it relaxes the system a bit because you can compare datetime.date en datetime.datetime objects.

> We do not want to allow that (kike Python does not allow).
> We must allow to compare only the same type and the PYSON should check the types.

Ok, I will keep the checks. I have also the checking in Sao working.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2019-08-08.12:41:18
> And it relaxes the system a bit because you can compare datetime.date en datetime.datetime objects.

We do not want to allow that (kike Python does not allow).
We must allow to compare only the same type and the PYSON should check the types.
Author: [hidden] (edbo)
Date: 2019-08-08.12:33:10
Which means, kind of implementing the added pyson.diff
Author: [hidden] (edbo)
Date: 2019-08-08.12:31:43
IMO the code really looks ugly and cumber stone. I'm wondering if it is not better to just convert the datetime.date and datetime.datetime to a UNIX timestamp (https://en.wikipedia.org/wiki/Unix_time). It makes everything a lot easier and look better because date and time are both converted to seconds (example https://duckduckgo.com/?q=time+since+epoch&atb=v112-1&ia=answer). And it relaxes the system a bit because you can compare datetime.date en datetime.datetime objects.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2019-08-02.09:57:03
> is also means updating the pyson functions on the client side.

pyson should be the same on server side and on client side, so for me it makes completly sense to update the functions on client side also. 

In order to do some change on pyson you should add a test on test_pyson.py (from trytond) and apply the same changes to pyson.py of tryton repository (there is no need to test on tryton as the code is the same as trytond). For sao things are a little bit different as you have to add the tests also (converting python code to javascript). Here is an example of a patch modifying pyson: 

https://codereview.tryton.org/287841003/

Hope it helps!
Author: [hidden] (edbo)
Date: 2019-08-01.18:33:34
> About the proposed patch, I don't think we should convert Date and DateTime to float?

When not converting to float, is also means updating the pyson functions on the client side. So what are your opinions on that.
Author: [hidden] (edbo)
Date: 2019-08-01.17:04:18
If nobody wants to pick it up, I will. I ran into this.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-08-18.10:43:43
Please follow http://www.tryton.org/how-to-contribute.html
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-08-18.10:43:26
Please follow http://www.tryton.org/how-to-contribute.html in order to contribute it. 

About the proposed patch, I don't think we should convert Date and DateTime to float?

P.S: If you need further asistence you can ping me on irc channel (pokoli) or ask in the mailing list.
Author: [hidden] (amon-ra)
Date: 2017-08-18.10:34:25
I have added Date comparison converting it to float, hope it helps.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2016-03-30.13:32:40
Decimal is also missing.
Author: [hidden] (guillemNaN)
Date: 2015-07-16.12:50:03
> But in this case both side should be of date type or datetime type.

Yes, of course.
To be consistent with domains, it must to force that both are date or both are datetime.

Another improvement could be (but it requires to discuss the details) to suport compare date with datetime or almost, have the datetime to date casting.
An example, you have a period that defines start and end date (fields.Date) and another object that has a DateTime field that must to be inside the period.
Now, tryton doesn't suport a domain like that (start is a DateTime field and period_start/end are Date):
[
('start', '>=', Eval('period_start')),
('start', '<=', Eval('period_end')),
]
But as I said, I think this improvement is another issue.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2015-07-16.11:23:20
But in this case both side should be of date type or datetime type.
Author: [hidden] (guillemNaN)
Date: 2015-07-16.10:15:18
The Greater/Less Pyson statements have the limitation to only accept int/long/float fields (pyson.py#L316).
It should accept also Date and DateTime fields.

I found this limitation trying to put this pyson statement in a field context:
'stock_move_date': max(Eval('planned_date', Date()), Eval('effective_date', Date()))
History
Date User Action Args
2020-09-05 23:00:17roundup-botsetmessages: + msg59977
2020-09-05 23:00:12roundup-botsetmessages: + msg59976
2020-09-05 23:00:09roundup-botsetmessages: + msg59975
2020-09-05 23:00:05roundup-botsetmessages: + msg59974
2020-09-05 23:00:01roundup-botsetstatus: testing -> resolved
nosy: + roundup-bot
messages: + msg59973
2020-08-04 00:51:39reviewbotsetmessages: + msg59604
2020-08-04 00:45:39cedsetassignedto: edbo -> ced
2020-04-09 19:31:18reviewbotsetmessages: + msg56955
2020-04-09 18:37:17reviewbotsetmessages: + msg56954
2020-01-02 21:01:44reviewbotsetmessages: + msg54731

Showing 10 items. Show all history (warning: this could be VERY long)