← Back to team overview

openerp-community team mailing list archive

Re: How to use datetime + timedelta on odoo filters

 

Also, using in filters
    (datetime.datetime.now()+relativedelta(hours=6)).strftime('%Y-%m-%d
%H:%M:%S')

is  not working on v8.  Would this be solved with web_relativedelta module ?
I checked and it is not in use even on 7.0...

Has that been deprecated on xml files ?



On Sun, Sep 28, 2014 at 11:48 PM, Holger Brunn <hbrunn@xxxxxxxx> wrote:

> Hi Mario,
>
> > Example:
> > If user timezone is GMT-6:00, then any of current "Today" filters will
> > filter only records from tomorrow if current local time is after 18:00
> >  (18:00 + 6:00 = 24:00 -->> next day).
>
> this is caused by https://bugs.launchpad.net/ocb-server/7.0/+bug/1255612,
> my
> patch should still work for 8.0, I think:
> https://github.com/odoo/odoo/blob/8.0/openerp/osv/expression.py#L1040
>
> > I was trying to adjust for that replacing time.strftime('%Y-%m-%d') with
> >
> > (datetime.datetime.now()+datetime.timedelta(hours=6)).strftime('%Y-%m-%d
> >  %H:%M:%S')
> > as all records created today after 18:00 will have a database timestamp
> of
> > tomorrow...
> > Problem is JS complains about invalid operands for "+": datetime and
> > timedelta...
>
> That's because the '+' operator is only defined on timedelta + timedelta:
>
> https://github.com/odoo/odoo/blob/8.0/addons/web/static/src/js/pyeval.js#L302
>
> > Any idea how could this be acomplished ?
>
> (datetime.datetime.now()+relativedelta(hours=6)).strftime('%Y-%m-%d
> %H:%M:%S')
>
> but I think you won't be completely happy with that, as what you actually
> want
> to search for is presumingly:
> [utc representation of $localdate 00:00:00] <= date_field <= [utc
> representation of $localdate 23:59:59]
> and that's where the above patch comes in handy.
>
> Regards,
> Holger
> --
> Therp - Maatwerk in open ontwikkeling
>
> Holger Brunn - Ontwerp en implementatie
>
> mail: holger@xxxxxxxx
> web: http://therp.nl
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-community
> Post to     : openerp-community@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openerp-community
> More help   : https://help.launchpad.net/ListHelp
>
>

References