Tryton - Issues

 

Issue4879

Title Suport Date, DateTime and Decimal fields in Greater/Less Pyson statement
Priority feature Status testing
Superseder Nosy List amon-ra, ced, edbo, guillemNaN, pokoli, resteve, reviewbot
Type feature request Components proteus, sao, tryton, trytond
Assigned To edbo Keywords patch, review
Reviews 270061002
View: 270061002

Created on 2015-07-16.10:15:19 by guillemNaN, last changed by reviewbot.

Files
File name Uploaded Type Edit Remove
pyson.diff amon-ra, 2017-08-18.10:34:25 text/plain
Messages
review270061002 updated at https://codereview.tryton.org/270061002/#ps254281002
review270061002 updated at https://codereview.tryton.org/270061002/#ps288051002
review270061002 updated at https://codereview.tryton.org/270061002/#ps280001002
review270061002 updated at https://codereview.tryton.org/270061002/#ps267861003
review270061002 updated at https://codereview.tryton.org/270061002/#ps277731002
review270061002 updated at https://codereview.tryton.org/270061002/#ps257921002
review270061002 updated at https://codereview.tryton.org/270061002/#ps279911002
msg51128 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2019-08-08.15:25:58
It is probably better to use momentjs comparison.
msg51127 (view) 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/
msg51126 (view) 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.
msg51121 (view) 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.
msg51120 (view) Author: [hidden] (edbo) Date: 2019-08-08.12:33:10
Which means, kind of implementing the added pyson.diff
msg51119 (view) 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.
review270061002 updated at https://codereview.tryton.org/270061002/#ps264031002
review270061002 updated at https://codereview.tryton.org/270061002/#ps281981002
New review270061002 at https://codereview.tryton.org/270061002/#ps279851002
msg51027 (view) 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!
msg51022 (view) 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.
msg51016 (view) Author: [hidden] (edbo) Date: 2019-08-01.17:04:18
If nobody wants to pick it up, I will. I ran into this.
msg35253 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2017-08-18.10:43:43
Please follow http://www.tryton.org/how-to-contribute.html
msg35252 (view) 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.
msg35251 (view) Author: [hidden] (amon-ra) Date: 2017-08-18.10:34:25
I have added Date comparison converting it to float, hope it helps.
msg25321 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2016-03-30.13:32:40
Decimal is also missing.
msg21920 (view) 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.
msg21917 (view) 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.
msg21916 (view) 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
2019-09-13 13:43:33reviewbotsetmessages: + msg51836
2019-09-12 19:19:02reviewbotsetmessages: + msg51816
2019-08-29 12:58:16reviewbotsetmessages: + msg51556
2019-08-29 11:35:19reviewbotsetmessages: + msg51555
2019-08-21 17:26:12reviewbotsetmessages: + msg51384
2019-08-13 00:04:47cedsetstatus: chatting -> testing
assignedto: edbo
component: + tryton, trytond, proteus, sao
2019-08-09 11:22:10reviewbotsetmessages: + msg51144
2019-08-08 23:53:39reviewbotsetmessages: + msg51141
2019-08-08 15:25:58cedsetmessages: + msg51128
2019-08-08 15:04:32edbosetmessages: + msg51127
2019-08-08 15:00:09edbosetmessages: + msg51126
2019-08-08 12:41:18cedsetmessages: + msg51121
2019-08-08 12:33:10edbosetmessages: + msg51120
2019-08-08 12:31:44edbosetmessages: + msg51119
2019-08-08 00:17:35reviewbotsetmessages: + msg51109
2019-08-07 23:51:59reviewbotsetmessages: + msg51108
2019-08-02 20:38:29reviewbotsetnosy: + reviewbot
messages: + msg51035
2019-08-02 20:38:28reviewbotsetreviews: 270061002
keyword: + review
2019-08-02 09:57:03pokolisetmessages: + msg51027
2019-08-01 18:33:34edbosetmessages: + msg51022
2019-08-01 17:04:19edbosetnosy: + edbo
messages: + msg51016
2017-08-18 10:43:43cedsetmessages: + msg35253
2017-08-18 10:43:26pokolisetmessages: + msg35252
2017-08-18 10:34:25amon-rasetfiles: + pyson.diff
nosy: + amon-ra
messages: + msg35251
keyword: + patch
2016-03-30 14:04:05restevesetnosy: + resteve
2016-03-30 13:37:16pokolisetnosy: + pokoli
2016-03-30 13:32:41cedsetmessages: + msg25321
title: Suport Date and DateTime fields in Greater/Less Pyson statement -> Suport Date, DateTime and Decimal fields in Greater/Less Pyson statement
2015-07-16 12:50:04guillemNaNsetmessages: + msg21920
2015-07-16 11:23:20cedsetstatus: unread -> chatting
nosy: + ced
messages: + msg21917
2015-07-16 10:15:20guillemNaNcreate