From ef84d5c4216ec1fa999df50834f378fc47c0dd05 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 4 Apr 2013 11:21:34 +0200 Subject: [PATCH] [FIX] sale_stock,purchase: review help string + remove incorrect fallback to local TZ See also http://bugs.python.org/issue7229 bzr revid: odo@openerp.com-20130404092134-0zt7blbl1kt3p0lz --- addons/purchase/company.py | 9 ++++++--- addons/purchase/purchase.py | 31 +++++++++++++++---------------- addons/sale_stock/company.py | 9 ++++++--- addons/sale_stock/sale_stock.py | 31 +++++++++++++++---------------- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/addons/purchase/company.py b/addons/purchase/company.py index 307c0c43d70..7a5d26a1b52 100644 --- a/addons/purchase/company.py +++ b/addons/purchase/company.py @@ -24,9 +24,12 @@ from openerp.osv import osv,fields class company(osv.osv): _inherit = 'res.company' _columns = { - 'po_lead': fields.float('Purchase Lead Time', required=True, - help="This is the leads/security time for each purchase order. For company security purpose this"\ - "many days will be removed from the date what suppliers has promised to you."), + 'po_lead': fields.float( + 'Purchase Lead Time', required=True, + help="Margin of error for supplier lead times. When the system"\ + "generates Purchase Orders for procuring products,"\ + "they will be scheduled that many days earlier "\ + "to cope with unexpected supplier delays."), } _defaults = { 'po_lead': lambda *a: 1.0, diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 1041b016fb3..3446d71c0e5 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -596,27 +596,26 @@ class purchase_order(osv.osv): return True def date_to_datetime(self, cr, uid, userdate, context=None): + """ Convert date values expressed in user's timezone to + server-side UTC timestamp, assuming a default arbitrary + time of 12:00 AM - because a time is needed. + + :param str userdate: date string in in user time zone + :return: UTC datetime string for server-side use """ - Function accepts date string assumed in client TZ and result is produced - in UTC timezone with 12:00 is assumed time to be sure, that system will - avoid tz date converstion issues. - e.g. Date 2013-03-26 in user tz will get 12:00 Hours and will then - get converted to UTC to avoid tz converstion. - userdate: date string in in user time zone. - return : the utc datetime string. - """ + # TODO: move to fields.datetime in server after 7.0 user_datetime = datetime.strptime(userdate, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(hours=12.0) if context and context.get('tz'): - tz_name = context['tz'] + tz_name = context['tz'] else: tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz'] - if not tz_name: - tz_name = time.tzname[time.daylight] - utc = pytz.timezone('UTC') - context_tz = pytz.timezone(tz_name) - local_timestamp = context_tz.localize(user_datetime, is_dst=False) - user_datetime = local_timestamp.astimezone(utc) - return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + if tz_name: + utc = pytz.timezone('UTC') + context_tz = pytz.timezone(tz_name) + local_timestamp = context_tz.localize(user_datetime, is_dst=False) + user_datetime = local_timestamp.astimezone(utc) + return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + return userdate def _prepare_order_picking(self, cr, uid, order, context=None): return { diff --git a/addons/sale_stock/company.py b/addons/sale_stock/company.py index cd07df3f744..eb2d644e57b 100644 --- a/addons/sale_stock/company.py +++ b/addons/sale_stock/company.py @@ -24,9 +24,12 @@ from openerp.osv import fields, osv class company(osv.osv): _inherit = 'res.company' _columns = { - 'security_lead': fields.float('Security Days', required=True, - help="For company security purpose this many days will be removed from the date, what you have promised to customers,"\ - "to cope up with any problems of procurement, final shipping, order negotiation etc."), + 'security_lead': fields.float( + 'Security Days', required=True, + help="Margin of error for dates promised to customers. "\ + "Products will be scheduled for procurement and delivery "\ + "that many days earlier than the actual promised date, to "\ + "cope with unexpected delays in the supply chain."), } _defaults = { 'security_lead': 0.0, diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 3fb41895d6e..a2246c78481 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -236,27 +236,26 @@ class sale_order(osv.osv): return res def date_to_datetime(self, cr, uid, userdate, context=None): + """ Convert date values expressed in user's timezone to + server-side UTC timestamp, assuming a default arbitrary + time of 12:00 AM - because a time is needed. + + :param str userdate: date string in in user time zone + :return: UTC datetime string for server-side use """ - Function accepts date string assumed in client TZ and result is produced - in UTC timezone with 12:00 is assumed time to be sure, that system will - avoid tz date converstion issues. - e.g. Date 2013-03-26 in user tz will get 12:00 Hours and will then - get converted to UTC to avoid tz converstion. - userdate: date string in in user time zone. - return : the utc datetime string. - """ + # TODO: move to fields.datetime in server after 7.0 user_datetime = datetime.strptime(userdate, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(hours=12.0) if context and context.get('tz'): - tz_name = context['tz'] + tz_name = context['tz'] else: tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz'] - if not tz_name: - tz_name = time.tzname[time.daylight] - utc = pytz.timezone('UTC') - context_tz = pytz.timezone(tz_name) - local_timestamp = context_tz.localize(user_datetime, is_dst=False) - user_datetime = local_timestamp.astimezone(utc) - return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + if tz_name: + utc = pytz.timezone('UTC') + context_tz = pytz.timezone(tz_name) + local_timestamp = context_tz.localize(user_datetime, is_dst=False) + user_datetime = local_timestamp.astimezone(utc) + return user_datetime.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + return userdate # if mode == 'finished': # returns True if all lines are done, False otherwise