[FIX] sale_order_dates yml fixed + calls to fields.date.date_to_datetime function fixed + improved in order to use it in purchase as well

bzr revid: qdp-launchpad@openerp.com-20140416154830-ec6kbs3bupd4j5vt
This commit is contained in:
Quentin (OpenERP) 2014-04-16 17:48:30 +02:00
parent 6d21e85454
commit dd47f684f0
3 changed files with 8 additions and 32 deletions

View File

@ -638,29 +638,6 @@ class purchase_order(osv.osv):
self.signal_purchase_cancel(cr, uid, ids)
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
"""
# TODO: move to fields.datetime in server after 7.0
user_date = datetime.strptime(userdate, DEFAULT_SERVER_DATE_FORMAT)
if context and context.get('tz'):
tz_name = context['tz']
else:
tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz']
if tz_name:
utc = pytz.timezone('UTC')
context_tz = pytz.timezone(tz_name)
user_datetime = user_date + relativedelta(hours=12.0)
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 user_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, group_id, context=None):
''' prepare the stock move data from the PO line. This function returns a list of dictionary ready to be used in stock.move's create()'''
product_uom = self.pool.get('product.uom')
@ -676,8 +653,8 @@ class purchase_order(osv.osv):
'product_id': order_line.product_id.id,
'product_uom': order_line.product_uom.id,
'product_uos': order_line.product_uom.id,
'date': self.date_to_datetime(cr, uid, order.date_order, context),
'date_expected': self.date_to_datetime(cr, uid, order_line.date_planned, context),
'date': fields.date.date_to_datetime(self, cr, uid, order.date_order, context),
'date_expected': fields.date.date_to_datetime(self, cr, uid, order_line.date_planned, context),
'location_id': order.partner_id.property_stock_supplier.id,
'location_dest_id': order.location_id.id,
'picking_id': picking_id,

View File

@ -37,7 +37,7 @@ class sale_order_dates(osv.osv):
def _get_date_planned(self, cr, uid, order, line, start_date, context=None):
"""Compute the expected date from the requested date, not the order date"""
if order and order.requested_date:
planned_str = fields.date.date_to_datetime(cr, uid, order.requested_date, context)
planned_str = fields.date.date_to_datetime(self, cr, uid, order.requested_date, context)
date_planned = datetime.strptime(planned_str, DEFAULT_SERVER_DATETIME_FORMAT)
date_planned -= timedelta(days=order.company_id.security_lead)
return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT)

View File

@ -18,13 +18,12 @@
!python {model: sale.order}: |
from datetime import datetime, timedelta
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
from openerp.fields import date
from openerp.osv import fields
so = self.browse(cr, uid, ref("sale.sale_order_6"))
security_delay = timedelta(days=so.company_id.security_lead)
requested_date = datetime.strptime(date.date_to_datetime(cr, uid, so.requested_date), DEFAULT_SERVER_DATETIME_FORMAT)
requested_date = datetime.strptime(fields.date.date_to_datetime(self, cr, uid, so.requested_date), DEFAULT_SERVER_DATETIME_FORMAT)
right_date = (requested_date - security_delay).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
for line in so.order_line:
assert line.procurement_id, "No Procurement was created"
assert line.procurement_id.date_planned == right_date, "The planned date for the Procurement Order is wrong"
assert line.procurement_id.move_id.date_expected == right_date, "The expected date for the Stock Move is wrong"
assert line.procurement_ids, "No Procurement was created"
assert line.procurement_ids[0].date_planned == right_date, "The planned date for the Procurement Order is wrong"
assert line.procurement_ids[0].move_ids and line.procurement_ids[0].move_ids[0].date_expected == right_date, "The expected date for the Stock Move is wrong"