[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
This commit is contained in:
Olivier Dony 2013-04-04 11:21:34 +02:00
parent ff481fab60
commit ef84d5c421
4 changed files with 42 additions and 38 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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,

View File

@ -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