[FIX] Remove timezoning in stock_calendar
Commit 64e1c28e3 introduced timezoning in resource_calendar in resource already.
This broke the stock_calendar module, but as such, the timezoning in the module
is not necessary anymore. All dates calculated from the times in the calendar
are calculated back to UTC and the results are without timezone in UTC. That way,
timezones are also not needed for calculating the leaves.
This commit is contained in:
@@ -29,8 +29,8 @@ class procurement_order(osv.osv):
|
||||
date_planned = datetime.strptime(procurement.date_planned, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
purchase_date, delivery_date = self._get_previous_dates(cr, uid, orderpoint, date_planned, context=context)
|
||||
if purchase_date and delivery_date:
|
||||
self.write(cr, uid, {'next_delivery_date': self._convert_to_UTC(cr, uid, delivery_date, context=context).strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
'next_purchase_date': self._convert_to_UTC(cr, uid, purchase_date, context=context).strftime(DEFAULT_SERVER_DATETIME_FORMAT),}, context=context)
|
||||
self.write(cr, uid, {'next_delivery_date': delivery_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
'next_purchase_date': purchase_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),}, context=context)
|
||||
|
||||
def _get_purchase_order_date(self, cr, uid, procurement, company, schedule_date, context=None):
|
||||
"""Return the datetime value to use as Order Date (``date_order``) for the
|
||||
@@ -84,8 +84,6 @@ class procurement_order(osv.osv):
|
||||
att_obj = self.pool.get('resource.calendar.attendance')
|
||||
context = context or {}
|
||||
context['no_round_hours'] = True
|
||||
# Date should be converted to the correct timezone
|
||||
start_date = self._convert_to_tz(cr, uid, start_date, context=context)
|
||||
# First check if the orderpoint has a Calendar as it should be delivered at this calendar date
|
||||
purchase_date = False
|
||||
delivery_date = start_date
|
||||
@@ -114,8 +112,8 @@ class procurement_order(osv.osv):
|
||||
context = context or {}
|
||||
context['no_round_hours'] = True
|
||||
if not new_date:
|
||||
new_date = self._convert_to_tz(cr, uid, datetime.utcnow(), context=context)
|
||||
now_date = self._convert_to_tz(cr, uid, datetime.utcnow(), context=context)
|
||||
new_date = datetime.utcnow()
|
||||
now_date = datetime.utcnow()
|
||||
|
||||
# Search first calendar day (without group)
|
||||
res = calendar_obj._schedule_days(cr, uid, orderpoint.calendar_id.id, 1, new_date, compute_leaves=True, context=context)
|
||||
@@ -157,21 +155,6 @@ class procurement_order(osv.osv):
|
||||
return (date1, res[0][1])
|
||||
return (False, False)
|
||||
|
||||
def _convert_to_tz(self, cr, uid, date, context=None):
|
||||
if not context or not context.get('tz'):
|
||||
return date
|
||||
utc_date = pytz.UTC.localize(date)
|
||||
timezone = pytz.timezone(context['tz'])
|
||||
return utc_date.astimezone(timezone)
|
||||
|
||||
def _convert_to_UTC(self, cr, uid, date, context=None):
|
||||
"""
|
||||
The date should be timezone aware
|
||||
"""
|
||||
if not context or not context.get('tz'):
|
||||
return date
|
||||
return date.astimezone(pytz.UTC)
|
||||
|
||||
def _get_group(self, cr, uid, orderpoint, context=None):
|
||||
"""
|
||||
Will return the groups and the end dates of the intervals of the purchase calendar
|
||||
@@ -186,15 +169,13 @@ class procurement_order(osv.osv):
|
||||
context = context or {}
|
||||
context['no_round_hours'] = True
|
||||
date = False
|
||||
now_date = self._convert_to_tz(cr, uid, datetime.utcnow(), context=context)
|
||||
now_date = datetime.utcnow()
|
||||
res_intervals = []
|
||||
if orderpoint.purchase_calendar_id and orderpoint.purchase_calendar_id.attendance_ids:
|
||||
if orderpoint.last_execution_date:
|
||||
new_date = datetime.strptime(orderpoint.last_execution_date, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
else:
|
||||
new_date = datetime.utcnow()
|
||||
# Convert to timezone of user
|
||||
new_date = self._convert_to_tz(cr, uid, new_date, context=context)
|
||||
intervals = calendar_obj._schedule_days(cr, uid, orderpoint.purchase_calendar_id.id, 1, new_date, compute_leaves=True, context=context)
|
||||
for interval in intervals:
|
||||
# If last execution date, interval should start after it in order not to execute the same orderpoint twice
|
||||
@@ -264,8 +245,8 @@ class procurement_order(osv.osv):
|
||||
date = res_group[1]
|
||||
subtract_qty = orderpoint_obj.subtract_procurements_from_orderpoints(cr, uid, [x.id for x in ops_dict[key]], context=context)
|
||||
first_op = True
|
||||
ndelivery = date and self._convert_to_UTC(cr, uid, date, context=context) or False
|
||||
npurchase = res_group[3] and self._convert_to_UTC(cr, uid, res_group[3], context=context) or False
|
||||
ndelivery = date
|
||||
npurchase = res_group[3]
|
||||
for op in ops_dict[key]:
|
||||
try:
|
||||
prods = prod_qty[op.product_id.id]['virtual_available']
|
||||
|
||||
@@ -48,21 +48,16 @@ class resource_calendar(osv.osv):
|
||||
leave intervals
|
||||
"""
|
||||
resource_calendar = self.browse(cr, uid, id, context=context)
|
||||
proc_obj = self.pool.get("procurement.order")
|
||||
leaves = []
|
||||
for leave in resource_calendar.leave_ids:
|
||||
if leave.resource_id and not resource_id == leave.resource_id.id:
|
||||
continue
|
||||
date_from_db = datetime.datetime.strptime(leave.date_from, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
date_from = proc_obj._convert_to_tz(cr, uid, date_from_db, context=context)
|
||||
date_from = datetime.datetime.strptime(leave.date_from, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
if end_datetime and date_from > end_datetime:
|
||||
continue
|
||||
|
||||
date_to_db = datetime.datetime.strptime(leave.date_to, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
date_to = proc_obj._convert_to_tz(cr, uid, date_to_db, context=context)
|
||||
date_to = datetime.datetime.strptime(leave.date_to, DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
if start_datetime and date_to < start_datetime:
|
||||
continue
|
||||
|
||||
leaves.append((date_from, date_to, leave.group_id.id))
|
||||
return leaves
|
||||
|
||||
|
||||
Reference in New Issue
Block a user