Merge lp:~openerp-dev/openerp-web/7.0-opw-591255-msh into lp:openerp-web/7.0

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openerp-web/7.0-opw-591255-msh
Merge into: lp:openerp-web/7.0
Diff against target: 27 lines (+10/-0)
1 file modified
addons/web/static/src/js/pyeval.js (+10/-0)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/7.0-opw-591255-msh
Reviewer Review Type Date Requested Status
Xavier (Open ERP) (community) Needs Fixing
Martin Trigaux (OpenERP) Pending
Nicolas Vanhoren (OpenERP) Pending
Review via email: mp+158867@code.launchpad.net

Description of the change

Hello,

Fixed the issue of datetime.date.today and datetime.datetime.today which is not supported by pyeval, so add today method to allow developed to use datetime.date.today, as server addons developer will always write a code in terms of python(by thinking python's datetime.datetime.today method).

Demo:- To reproduce this issue create one search filter for date field as follow.

<filter icon="terp-go-month"
        string="Past 7 Days"
        domain="[('date_order','&lt;=', (datetime.date.today() + relativedelta(days=-7)).strftime('%%Y-%%m-%%d 23:59:59'))]" />

Or create for datetime field as follow.

<filter icon="terp-go-month"
        string="Past 7 Days"
        domain="[('date_order','&lt;=', (datetime.datetime.today()).strftime('%%Y-%%m-%%d 23:59:59'))]"/>

Noe goto search view and click on this filter and you will get error results.group_by is undefined.

Reason: today is not supported by datetime.date or datetime.datetime object(pyeval.js helper of py.js), as python datetime.datetime object has today method which gives localtime without tz information so we should support this as server addons developer will put domain by considering python.

Thanks.

To post a comment you must log in.
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

* Why doesn't datetime.datetime.today just call datetime.datetime.now since they're equivalent if timezones aren't supported?

* I expect the whole point of context_today is that using date.today is *wrong*. If that's the case, it definitely should not be added. Though you'll have to check that with niv.

review: Needs Fixing
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

(or maybe not, I don't know, in any case please ask niv for #2)

Unmerged revisions

3892. By Mohammed Shekha<email address hidden>

[FIX]Fixed the issue of datetime.date.today and datetime.datetime.today which is not supported by pyeval, so add today method to allow developed to use datetime.date.today, as server addons developer will always write a code in terms of python(by thinking python's datetime.datetime.today method).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/pyeval.js'
2--- addons/web/static/src/js/pyeval.js 2013-03-19 10:27:19 +0000
3+++ addons/web/static/src/js/pyeval.js 2013-04-15 09:01:26 +0000
4@@ -402,6 +402,13 @@
5 d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(),
6 d.getUTCMilliseconds() * 1000]);
7 }),
8+ today: py.classmethod.fromJSON(function(){
9+ var d = new Date();
10+ return py.PY_call(datetime.datetime,
11+ [d.getFullYear(), d.getMonth() + 1, d.getDate(),
12+ d.getHours(), d.getMinutes(), d.getSeconds(),
13+ d.getMilliseconds() * 1000]);
14+ }),
15 combine: py.classmethod.fromJSON(function () {
16 var args = py.PY_parseArgs(arguments, 'date time');
17 return py.PY_call(datetime.datetime, [
18@@ -467,6 +474,9 @@
19 },
20 fromJSON: function (year, month, day) {
21 return py.PY_call(datetime.date, [year, month, day])
22+ },
23+ today: function() {
24+ return context_today()
25 }
26 });
27 /**