Commit fa27fb9c authored by Alexandre Boeglin's avatar Alexandre Boeglin

get date delta in milliseconds, to avoid rounding issues

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16081 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7ad578de
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
from TargetSolver import TargetSolver from TargetSolver import TargetSolver
from Products.ERP5Type.DateUtils import createDateTimeFromMillis
class CopyToTarget(TargetSolver): class CopyToTarget(TargetSolver):
""" """
...@@ -61,10 +62,11 @@ class CopyToTarget(TargetSolver): ...@@ -61,10 +62,11 @@ class CopyToTarget(TargetSolver):
quantity_ratio = new_quantity / old_quantity quantity_ratio = new_quantity / old_quantity
start_date_delta = 0 start_date_delta = 0
stop_date_delta = 0 stop_date_delta = 0
# get the date delta in milliseconds, to prevent rounding issues
if new_start_date is not None and old_start_date is not None: if new_start_date is not None and old_start_date is not None:
start_date_delta = new_start_date - old_start_date start_date_delta = new_start_date.millis() - old_start_date.millis()
if new_stop_date is not None and old_stop_date is not None: if new_stop_date is not None and old_stop_date is not None:
stop_date_delta = new_stop_date - old_stop_date stop_date_delta = new_stop_date.millis() - old_stop_date.millis()
return { return {
'quantity_ratio': quantity_ratio, 'quantity_ratio': quantity_ratio,
'start_date_delta': start_date_delta, 'start_date_delta': start_date_delta,
...@@ -89,10 +91,10 @@ class CopyToTarget(TargetSolver): ...@@ -89,10 +91,10 @@ class CopyToTarget(TargetSolver):
# Modify quantity, start_date, stop_date # Modify quantity, start_date, stop_date
start_date = simulation_movement.getStartDate() start_date = simulation_movement.getStartDate()
if start_date is not None: if start_date is not None:
value_dict['start_date'] = start_date + start_date_delta value_dict['start_date'] = createDateTimeFromMillis(start_date.millis() + start_date_delta)
stop_date = simulation_movement.getStopDate() stop_date = simulation_movement.getStopDate()
if stop_date is not None: if stop_date is not None:
value_dict['stop_date'] = stop_date + stop_date_delta value_dict['stop_date'] = createDateTimeFromMillis(stop_date.millis() + stop_date_delta)
value_dict['quantity'] = simulation_movement.getQuantity() * quantity_ratio value_dict['quantity'] = simulation_movement.getQuantity() * quantity_ratio
return value_dict return value_dict
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
from CopyToTarget import CopyToTarget from CopyToTarget import CopyToTarget
from Products.ERP5Type.DateUtils import createDateTimeFromMillis
class ResourceBackpropagation(CopyToTarget): class ResourceBackpropagation(CopyToTarget):
""" """
...@@ -53,10 +54,11 @@ class ResourceBackpropagation(CopyToTarget): ...@@ -53,10 +54,11 @@ class ResourceBackpropagation(CopyToTarget):
quantity_ratio = new_quantity / old_quantity quantity_ratio = new_quantity / old_quantity
start_date_delta = 0 start_date_delta = 0
stop_date_delta = 0 stop_date_delta = 0
# get the date delta in milliseconds, to prevent rounding issues
if new_start_date is not None and old_start_date is not None: if new_start_date is not None and old_start_date is not None:
start_date_delta = new_start_date - old_start_date start_date_delta = new_start_date.millis() - old_start_date.millis()
if new_stop_date is not None and old_stop_date is not None: if new_stop_date is not None and old_stop_date is not None:
stop_date_delta = new_stop_date - old_stop_date stop_date_delta = new_stop_date.millis() - old_stop_date.millis()
return { return {
'quantity_ratio': quantity_ratio, 'quantity_ratio': quantity_ratio,
'start_date_delta': start_date_delta, 'start_date_delta': start_date_delta,
...@@ -82,10 +84,10 @@ class ResourceBackpropagation(CopyToTarget): ...@@ -82,10 +84,10 @@ class ResourceBackpropagation(CopyToTarget):
# Modify quantity, start_date, stop_date # Modify quantity, start_date, stop_date
start_date = simulation_movement.getStartDate() start_date = simulation_movement.getStartDate()
if start_date is not None: if start_date is not None:
value_dict['start_date'] = start_date + start_date_delta value_dict['start_date'] = createDateTimeFromMillis(start_date.millis() + start_date_delta)
stop_date = simulation_movement.getStopDate() stop_date = simulation_movement.getStopDate()
if stop_date is not None: if stop_date is not None:
value_dict['stop_date'] = stop_date + stop_date_delta value_dict['stop_date'] = createDateTimeFromMillis(stop_date.millis() + stop_date_delta)
value_dict['quantity'] = simulation_movement.getQuantity() * quantity_ratio value_dict['quantity'] = simulation_movement.getQuantity() * quantity_ratio
if resource_list: if resource_list:
value_dict['resource_list'] = resource_list value_dict['resource_list'] = resource_list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment