Commit 777f564d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

remove duplicate codes by calling super class's methods.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23081 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c99565d6
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
############################################################################## ##############################################################################
from CopyToTarget import CopyToTarget from CopyToTarget import CopyToTarget
from Products.ERP5Type.DateUtils import createDateTimeFromMillis
class ResourceBackpropagation(CopyToTarget): class ResourceBackpropagation(CopyToTarget):
""" """
...@@ -40,36 +39,19 @@ class ResourceBackpropagation(CopyToTarget): ...@@ -40,36 +39,19 @@ class ResourceBackpropagation(CopyToTarget):
Get interesting values Get interesting values
XXX: better description is possible. But is it needed ? XXX: better description is possible. But is it needed ?
""" """
# Get interesting value value_delta_dict = CopyToTarget._generateValueDeltaDict(
old_quantity = simulation_movement.getQuantity() self, simulation_movement)
old_start_date = simulation_movement.getStartDate() value_delta_dict.update(
old_stop_date = simulation_movement.getStopDate() {
new_quantity = simulation_movement.getDeliveryQuantity() * \
simulation_movement.getDeliveryRatio()
new_start_date = simulation_movement.getDeliveryStartDateList()[0]
new_stop_date = simulation_movement.getDeliveryStopDateList()[0]
# Calculate delta
quantity_ratio = 0
if old_quantity not in (None,0.0): # XXX: What if quantity happens to be an integer ?
quantity_ratio = new_quantity / old_quantity
start_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:
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:
stop_date_delta = new_stop_date.millis() - old_stop_date.millis()
return {
'quantity_ratio': quantity_ratio,
'start_date_delta': start_date_delta,
'stop_date_delta': stop_date_delta,
'resource_list' : 'resource_list' :
simulation_movement.getDeliveryValue().getResourceList(), simulation_movement.getDeliveryValue().getResourceList(),
'variation_category_list': 'variation_category_list':
simulation_movement.getDeliveryValue().getVariationCategoryList(), simulation_movement.getDeliveryValue().getVariationCategoryList(),
'variation_property_dict': 'variation_property_dict':
simulation_movement.getDeliveryValue().getVariationPropertyDict(), simulation_movement.getDeliveryValue().getVariationPropertyDict(),
} })
return value_delta_dict
def _generateValueDict(self, simulation_movement, quantity_ratio=1, def _generateValueDict(self, simulation_movement, quantity_ratio=1,
start_date_delta=0, stop_date_delta=0, start_date_delta=0, stop_date_delta=0,
...@@ -80,15 +62,13 @@ class ResourceBackpropagation(CopyToTarget): ...@@ -80,15 +62,13 @@ class ResourceBackpropagation(CopyToTarget):
""" """
Generate values to save on simulation movement. Generate values to save on simulation movement.
""" """
value_dict = {} value_dict = CopyToTarget._generateValueDict(
# Modify quantity, start_date, stop_date self, simulation_movement, quantity_ratio=quantity_ratio,
start_date = simulation_movement.getStartDate() start_date_delta=start_date_delta, stop_date_delta=stop_date_delta,
if start_date is not None: resource_list=resource_list,
value_dict['start_date'] = createDateTimeFromMillis(start_date.millis() + start_date_delta) variation_category_list=variation_category_list,
stop_date = simulation_movement.getStopDate() variation_property_dict=variation_property_dict, **value_delta_dict)
if stop_date is not None: # Modify resource etc.
value_dict['stop_date'] = createDateTimeFromMillis(stop_date.millis() + stop_date_delta)
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
if variation_category_list: if variation_category_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