← 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

 

I can confirm it.

Ubuntu Precise server running the OpenERP server.
Ubuntu Lucid running the Postgres server

Create a new database through the OpenERP interface, set to English UK and load the demo data.
Set the Administrator user Timezone to Pacific/Auckland  (GMT+12)
Install the account_accountant module (Accounting and Finance)
Accounting >> Reporting >> Accounting Reports >> Legal Reports >> Trial Balance.

The date and time on the servers are ..
ian@dolven-openerp:~$ date
Thu Apr 19 08:36:00 NZST 2012

ian@dolven-db:~$ date
Thu Apr 19 08:35:56 NZST 2012

The time at the top of the Trial Balance report (attached) is 18/04/2012
20:36 which is last night, not this morning when I ran it.

** Attachment added: "account.account.balance.pdf"
   https://bugs.launchpad.net/openobject-server/+bug/979550/+attachment/3091261/+files/account.account.balance.pdf

-- 
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):
  Incomplete
Status in OpenERP Server:
  Incomplete

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