From 9f0120d73bbbc364d8ec04b0e3ad63c75086ba52 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 24 Feb 2016 18:21:19 +0100 Subject: [PATCH] [FIX] point_of_sale: Sales Details timezone The Sales Details report wizard gives the possibility to print the details of the POS orders between two dates. The fields in the wizard are of type `date`, while the orders dates are of type `datetime`. `00:00:00` and `23:59:59` were naively added to the `date_start` and `date_end` (respectively) to handle the case. But, this doesn't take care of the user time zone: When a user choose between February 24th and February 25th, it's within his time zone, and therefore, for the search, where the datetime are in UTC, adding `00:00:00` isn't enough, the dates have to be converted from the user time zone to UTC. opw-6698831 --- addons/point_of_sale/report/pos_details.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/report/pos_details.py b/addons/point_of_sale/report/pos_details.py index 3416c6f879d..ddf88763873 100644 --- a/addons/point_of_sale/report/pos_details.py +++ b/addons/point_of_sale/report/pos_details.py @@ -19,7 +19,10 @@ # ############################################################################## +import datetime +import pytz import time +from openerp import tools from openerp.report import report_sxw class pos_details(report_sxw.rml_parse): @@ -44,7 +47,22 @@ class pos_details(report_sxw.rml_parse): result = {} user_ids = form['user_ids'] or self._get_all_users() company_id = user_obj.browse(self.cr, self.uid, self.uid).company_id.id - pos_ids = pos_obj.search(self.cr, self.uid, [('date_order','>=',form['date_start'] + ' 00:00:00'),('date_order','<=',form['date_end'] + ' 23:59:59'),('user_id','in',user_ids),('state','in',['done','paid','invoiced']),('company_id','=',company_id)]) + user = self.pool['res.users'].browse(self.cr, self.uid, self.uid) or self.localcontext.get('tz') or 'UTC' + tz_name = user.tz + user_tz = pytz.timezone(tz_name) + between_dates = {} + for date_field, delta in {'date_start': {'days': 0}, 'date_end': {'days': 1}}.items(): + timestamp = datetime.datetime.strptime(form[date_field] + ' 00:00:00', tools.DEFAULT_SERVER_DATETIME_FORMAT) + datetime.timedelta(**delta) + timestamp = user_tz.localize(timestamp).astimezone(pytz.utc) + between_dates[date_field] = timestamp.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) + + pos_ids = pos_obj.search(self.cr, self.uid, [ + ('date_order', '>=', between_dates['date_start']), + ('date_order', '<', between_dates['date_end']), + ('user_id', 'in', user_ids), + ('state', 'in', ['done', 'paid', 'invoiced']), + ('company_id', '=', company_id) + ]) for pos in pos_obj.browse(self.cr, self.uid, pos_ids): for pol in pos.lines: result = {