Needing standard/good functions for date/time output in user's timezone for account reports
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Odoo Server (MOVED TO GITHUB) |
Confirmed
|
Low
|
OpenERP's Framework R&D |
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-
---- DIFF ----
index 27bd5fa..ad2c341 100644
--- a/openerp/
+++ b/openerp/
@@ -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):
'time' : time,
+ 'pytz': pytz,
+ 'datetime': datetime,
# 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.
Time: [[ datetime.
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/
Changed in openobject-server: | |
assignee: | nobody → OpenERP's Framework R&D (openerp-dev-framework) |
importance: | Undecided → Low |
status: | Incomplete → Confirmed |
no longer affects: | openobject-addons |
I would also like to add that these functions may be useful elsewhere in the general codebase.