[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
This commit is contained in:
parent
ce38582907
commit
9f0120d73b
|
@ -19,7 +19,10 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import pytz
|
||||||
import time
|
import time
|
||||||
|
from openerp import tools
|
||||||
from openerp.report import report_sxw
|
from openerp.report import report_sxw
|
||||||
|
|
||||||
class pos_details(report_sxw.rml_parse):
|
class pos_details(report_sxw.rml_parse):
|
||||||
|
@ -44,7 +47,22 @@ class pos_details(report_sxw.rml_parse):
|
||||||
result = {}
|
result = {}
|
||||||
user_ids = form['user_ids'] or self._get_all_users()
|
user_ids = form['user_ids'] or self._get_all_users()
|
||||||
company_id = user_obj.browse(self.cr, self.uid, self.uid).company_id.id
|
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 pos in pos_obj.browse(self.cr, self.uid, pos_ids):
|
||||||
for pol in pos.lines:
|
for pol in pos.lines:
|
||||||
result = {
|
result = {
|
||||||
|
|
Loading…
Reference in New Issue