← Back to team overview

openerp-community team mailing list archive

Re: How to use datetime + timedelta on odoo filters

 

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

Attachment: signature.asc
Description: This is a digitally signed message part.


Follow ups

References