I think that more safely get timezone shift from Web client than from python on server side. Because browser, as a rule, have a real local time. And users can forget to set the time zone in OpenERP preference, as well as once again there are problems with daylight saving time.
-- 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 _______________________________________________ Mailing list: https://launchpad.net/~openerp-india Post to : [email protected] Unsubscribe : https://launchpad.net/~openerp-india More help : https://help.launchpad.net/ListHelp

