[FIX] odoo-bin: server UTC timezone on windows

On UNIX, the timezone modules conversions can be reset by using
`time.tzset()`. On windows this is not available and the timezone (TZ)
environment variable must be set before the first import of time module.

If not, all datetime gotten in python without specifying UTC (such as
datetime.datetime.now) could be wrong.

This was fixed with 4a77c6a0 in 2013, but has come back since 389c2ba97b
imported pkg_resources (which do  a `time` module import) before that.

closes #14926
opw-693764
This commit is contained in:
Nicolas Lempereur
2017-01-06 14:19:09 +01:00
parent 56c798a323
commit 07bf7bf4f3
4 changed files with 10 additions and 8 deletions
+1
View File
@@ -908,5 +908,6 @@ class ReportSaleDetails(models.AbstractModel):
def render_html(self, docids, data=None):
data = dict(data or {})
configs = self.env['pos.config'].browse(data['config_ids'])
print(data['config_ids'])
data.update(self.get_sale_details(data['date_start'], data['date_stop'], configs))
return self.env['report'].render('point_of_sale.report_saledetails', data)
@@ -426,6 +426,7 @@ var FieldCharDomain = common.AbstractField.extend(common.ReinitializeFieldMixin,
this.do_warn(_t('Error: Bad domain'), _t('The domain is wrong.'));
return;
}
debugger; // EAADD
var ds = new data.DataSetStatic(self, model, self.build_context());
ds.call('search_count', [domain]).then(function (results) {
self.$('.o_count').text(results + _t(' selected records'));
+3
View File
@@ -1,4 +1,7 @@
#!/usr/bin/env python
# set server timezone in UTC before time module imported
__import__('os').environ['TZ'] = 'UTC'
__import__('pkg_resources').declare_namespace('odoo.addons')
import odoo
+5 -8
View File
@@ -27,15 +27,12 @@ multi_process = False
#----------------------------------------------------------
# libc UTC hack
#----------------------------------------------------------
# Make sure the OpenERP server runs in UTC. This is especially necessary
# under Windows as under Linux it seems the real import of time is
# sufficiently deferred so that setting the TZ environment variable
# in odoo.cli.server was working.
# Make sure the OpenERP server runs in UTC.
import os
os.environ['TZ'] = 'UTC' # Set the timezone...
import time # ... *then* import time.
del os
del time
os.environ['TZ'] = 'UTC' # Set the timezone
import time
if hasattr(time, 'tzset'):
time.tzset()
#----------------------------------------------------------
# Shortcuts