← Back to team overview

openerp-india team mailing list archive

[Bug 979550] Re: Needing standard/good functions for date/time output in user's timezone for account reports

 

But now, when working with Web client, OpenERP take time zone from browser, not from server, not from preference.
Then convert to UTC and send to server. There is no information to restore the local time.

If we relies on preference then need that web client also relies on it.
Because we save time with shift from TZ browser and then try restore
local time with shift from TZ preference.

Example:
We create data records with fild DATETIME in browser with TZ shift +4hours from UTC:
How look records for user in browser (TREE VIEW)
1.  2112-05-01 01:00:00
2.  2112-05-01 05:00:00
How look records in DB
1.  2112-04-30 21:00:00
2.  2112-05-01 01:00:00
User try make report, and wants select all records for month - MAY 2112. Browser send to server, that need select all records with YEAR = 2112 and MONTH = 05. That make it correct, server must convert date from records in DB to  TZ of user. But if TZ in preference (+2hours) not equal TZ in browser it receive wrong report:
Report for  browser user
1.  2112-05-01 03:00:00
But records looks for user in browser (TREE VIEW)
1.  2112-05-01 01:00:00
2.  2112-05-01 05:00:00
User expect that records in TREE VIEW and in report must be the same!

In addition, the more likely the fact that the browser has a real time
than the time zone in preference. Because user work with OS every day
and he view system time every day. But when the last time he change
preference OpenERP?

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/979550

Title:
  Needing standard/good functions for date/time output in user's
  timezone for account reports

Status in OpenERP Addons (modules):
  Invalid
Status in OpenERP Server:
  Confirmed

Bug description:
  I've run into a problem of not having correct timezones applied when
  generating reports. This is partly the fault of the server's timezone
  being forced to UTC, but also due to the lack of availability of easy-
  to-use functions in the templates used to generate these reports.

  What I have done as a proof of concept is to add "import pytz" into
  openobject-server/openerp/report/report_sxw.py, then add pytz and
  datetime into the localcontext member variable in rmlparse.

  ---- DIFF ----

  index 27bd5fa..ad2c341 100644
  --- a/openerp/report/report_sxw.py
  +++ b/openerp/report/report_sxw.py
  @@ -26,6 +26,7 @@ from datetime import datetime
   import os
   import re
   import time
  +import pytz
   from interface import report_rml
   import preprocess
   import logging
  @@ -168,6 +169,8 @@ class rml_parse(object):
               'setHtmlImage' : self.set_html_image,
               'strip_name' : self._strip_name,
               'time' : time,
  +            'pytz': pytz,
  +            'datetime': datetime,
               'display_address': self.display_address,
               # more context members are setup in setCompany() below:
               #  - company_id
  ---- DIFF ----

  This change allows me to call pytz and datetime from within the report
  templates (most specifically I've been looking at the internal
  header/footer templates for companies). I find this to be preferable
  over formatLang and time.strftime calls, which do not really allow for
  timezone changes. formatLang is something of an exception here - it is
  meant to take a date or datetime string of a particular format and
  correct the timezone for it, however this breaks easily, and seems
  superfluous.

  What I use currently for correct date and time in the templates are:
  Date: [[ datetime.now(python.timezone(tz)).strftime('%Y-%m-%d') ]]
  Time: [[ datetime.now(python.timezone(tz)).strftime('%H:%M') ]]

  What I think would be much better is easy access to standard objects/functions that will output dates, times and datetimes in the user's timezone. So that we might call them with something like:
  Date: [[ utime.today() ]]
  Time: [[ utime.localtime() ]]
  Datetime: [[ utime.now() ]]

  I would also like the flexibility to provide my own strftime string.
  I have no attachment to these names for functions/namespaces/objects.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/979550/+subscriptions


References