Commit c906b34c authored by Sebastien Robin's avatar Sebastien Robin

commit changes of guillaume


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1516 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4cd54037
...@@ -212,6 +212,34 @@ class SimulationTool (Folder, UniqueObject): ...@@ -212,6 +212,34 @@ class SimulationTool (Folder, UniqueObject):
def collectMovement(self, movement_list, def collectMovement(self, movement_list,
check_order = 1, check_path = 1, check_date = 1, check_criterion = 0, check_order = 1, check_path = 1, check_date = 1, check_criterion = 0,
check_resource = 1, check_base_variant = 0, check_variant = 1): check_resource = 1, check_base_variant = 0, check_variant = 1):
current_order = 2
check_list = [check_order, check_path, check_date, check_criterion, check_resource, check_base_variant, check_variant]
for i in range(len(check_list)):
if check_list[i]:
check_list[i] = current_order
current_order += 1
check_order = check_list[0]
check_path = check_list[1]
check_date = check_list[2]
check_criterion = check_list[3]
check_resource = check_list[4]
check_base_variant = check_list[5]
check_variant = check_list[6]
return self.orderedCollectMovement(movement_list=movement_list,
check_order=check_order,
check_path=check_path,
check_date=check_date,
check_criterion=check_criterion,
check_resource=check_resource,
check_base_variant=check_base_variant,
check_variant=check_variant)
def orderedCollectMovement(self, movement_list,
check_order = 2, check_path = 3, check_date = 4, check_criterion = 0,
check_resource = 5, check_base_variant = 0, check_variant = 6):
LOG('orderedCollectMovement :', 0, 'movement_list = %s' % repr(movement_list))
class RootGroup: class RootGroup:
...@@ -225,7 +253,10 @@ class SimulationTool (Folder, UniqueObject): ...@@ -225,7 +253,10 @@ class SimulationTool (Folder, UniqueObject):
""" """
This sets an appropriate nested class. This sets an appropriate nested class.
""" """
class_list = ((1, RootGroup), def cmpfunc(a,b):
return cmp(a[0],b[0])
class_list = [(1, RootGroup),
(check_order, OrderGroup), (check_order, OrderGroup),
(check_path, PathGroup), (check_path, PathGroup),
(check_date, DateGroup), (check_date, DateGroup),
...@@ -233,7 +264,8 @@ class SimulationTool (Folder, UniqueObject): ...@@ -233,7 +264,8 @@ class SimulationTool (Folder, UniqueObject):
(check_resource, ResourceGroup), (check_resource, ResourceGroup),
(check_base_variant, BaseVariantGroup), (check_base_variant, BaseVariantGroup),
(check_variant, VariantGroup), (check_variant, VariantGroup),
) ]
class_list.sort(cmpfunc)
for i in range(len(class_list)): for i in range(len(class_list)):
if class_list[i][1] == self.__class__: if class_list[i][1] == self.__class__:
break break
...@@ -562,14 +594,16 @@ class SimulationTool (Folder, UniqueObject): ...@@ -562,14 +594,16 @@ class SimulationTool (Folder, UniqueObject):
return order_list return order_list
def buildDeliveryList(self, movement_group): def buildDeliveryList(self, movement_group):
# Build deliveries from a list of movements # Build deliveries from a list of movements
delivery_list = []
reindexable_movement_list = []
if movement_group is not None: def orderGroupProcessing(order_group, delivery_list, reindexable_movement_list, **kw):
for order_group in movement_group.group_list:
# Order should never be None # Order should never be None
LOG("buildDeliveryList", 0, str(order_group.__dict__)) LOG("buildDeliveryList", 0, str(order_group.__dict__))
if order_group.order is not None: if order_group.order is not None:
...@@ -589,7 +623,7 @@ class SimulationTool (Folder, UniqueObject): ...@@ -589,7 +623,7 @@ class SimulationTool (Folder, UniqueObject):
delivery_cell_type = 'Delivery Cell' delivery_cell_type = 'Delivery Cell'
else : # should never be none else : # should never be none
LOG("order is None", 0, str(order.__dict__)) LOG("order is None", 0, str(order.__dict__))
return delivery_list return -1
else: # order is None else: # order is None
order = None order = None
# possible when we build deliveries for tranfer of property # possible when we build deliveries for tranfer of property
...@@ -598,9 +632,26 @@ class SimulationTool (Folder, UniqueObject): ...@@ -598,9 +632,26 @@ class SimulationTool (Folder, UniqueObject):
delivery_line_type = delivery_type + ' Line' delivery_line_type = delivery_type + ' Line'
delivery_cell_type = 'Delivery Cell' delivery_cell_type = 'Delivery Cell'
for path_group in order_group.group_list : for path_group in order_group.group_list:
pathGroupProcessing(path_group=path_group,
delivery_module=delivery_module,
delivery_type=delivery_type,
delivery_line_type=delivery_line_type,
delivery_cell_type=delivery_cell_type,
order=order,
delivery_list=delivery_list,
reindexable_movement_list=reindexable_movement_list, **kw)
return 0
def pathGroupProcessing(path_group, delivery_module, delivery_type, delivery_line_type, delivery_cell_type, order, delivery_list, reindexable_movement_list, default_rule_id=None, **kw):
# we create a new delivery for each DateGroup # we create a new delivery for each DateGroup
if default_rule_id is 'default_amortisation_rule':
pass
else:
# if path is internal ??? # if path is internal ???
# JPS NEW # JPS NEW
if path_group.source is None or path_group.destination is None: if path_group.source is None or path_group.destination is None:
...@@ -627,7 +678,82 @@ class SimulationTool (Folder, UniqueObject): ...@@ -627,7 +678,82 @@ class SimulationTool (Folder, UniqueObject):
delivery_cell_type = 'Delivery Cell' delivery_cell_type = 'Delivery Cell'
for date_group in path_group.group_list : for date_group in path_group.group_list :
dateGroupProcessing(date_group=date_group,
path_group=path_group,
delivery_module=delivery_module,
delivery_type=delivery_type,
delivery_line_type=delivery_line_type,
delivery_cell_type=delivery_cell_type,
order=order,
delivery_list=delivery_list,
reindexable_movement_list=reindexable_movement_list,
default_rule_id=default_rule_id, **kw)
def dateGroupProcessing(date_group, path_group, delivery_module, delivery_type, delivery_line_type, delivery_cell_type, order, delivery_list, reindexable_movement_list, default_rule_id=None, resource=None, **kw):
if default_rule_id == 'default_amortisation_rule':
accounting_transaction_data_list = {}
for path_group in date_group.group_list:
source_section = path_group.source_section
destination_section = path_group.destination_section
source = path_group.source
destination = path_group.destination
accounting_transaction_data = accounting_transaction_data_list.get( (source_section, destination_section), None)
if accounting_transaction_data is None:
accounting_transaction_data_list[ (source_section, destination_section) ] = {}
accounting_transaction_data = accounting_transaction_data_list.get( (source_section, destination_section), None)
quantity = 0
source_movement_list = []
for movement in path_group.movement_list:
if movement.getDeliveryValue() is None:
quantity += movement.getQuantity()
source_movement_list.append(movement)
LOG('buildDeliveryList :', 0, 'adding movement %s : quantity = %s' % (repr(movement), repr(movement.getQuantity())))
else:
LOG('buildDeliveryList :', 0, 'movement %s... delivery value = %s' % (repr(movement), repr(movement.getDeliveryValue())))
accounting_transaction_data[ (source, destination) ] = (quantity, source_movement_list)
if len(source_movement_list) == 0:
LOG('buildDeliveryList :', 0, 'deleting transaction line because no source movement list... path_group.movement_list = %s' % repr(path_group.movement_list))
del accounting_transaction_data[ (source, destination) ]
for (source_section, destination_section), accounting_transaction_data in accounting_transaction_data_list.items():
if len(accounting_transaction_data.items()) > 0:
new_delivery_id = str(delivery_module.generateNewId())
self.portal_types.constructContent(type_name = delivery_type,
container = delivery_module,
id = new_delivery_id,
target_start_date = date_group.start_date,
target_stop_date = date_group.stop_date,
start_date = date_group.start_date,
stop_date = date_group.stop_date,
source_section = source_section,
destination_section = destination_section
)
accounting_transaction = delivery_module[new_delivery_id]
accounting_transaction.setResource(resource)
for (source, destination), (quantity, source_movement_list) in accounting_transaction_data.items():
new_transaction_line_id = str(accounting_transaction.generateNewId())
self.portal_types.constructContent(type_name = delivery_line_type,
container = accounting_transaction,
id = new_transaction_line_id,
source = source,
destination = destination)
accounting_transaction_line = accounting_transaction[new_transaction_line_id]
accounting_transaction_line.setQuantity(quantity)
LOG('buildDeliveryList :', 0, 'setting resource for line %s... resource = %s' % (repr(accounting_transaction_line), repr(resource)))
accounting_transaction_line.setResource(resource)
for movement in source_movement_list:
LOG('buildDeliveryList :', 0, 'setting delivery value... movement = %s, accounting_transaction_line = %s' % (repr(movement), repr(accounting_transaction_line)))
movement.setDeliveryValue(accounting_transaction_line)
LOG('buildDeliveryList :', 0, 'after setting it, movement.delivery_value = %s' % repr(movement.getDeliveryValue()))
movement.recursiveImmediateReindexObject()
else:
# Create a new packing list # Create a new packing list
new_delivery_id = str(delivery_module.generateNewId()) new_delivery_id = str(delivery_module.generateNewId())
self.portal_types.constructContent(type_name = delivery_type, self.portal_types.constructContent(type_name = delivery_type,
...@@ -656,6 +782,33 @@ class SimulationTool (Folder, UniqueObject): ...@@ -656,6 +782,33 @@ class SimulationTool (Folder, UniqueObject):
# Create each delivery_line in the new delivery # Create each delivery_line in the new delivery
for resource_group in date_group.group_list : for resource_group in date_group.group_list :
resourceGroupProcessing(resource_group=resource_group,
delivery=delivery,
delivery_type=delivery_type,
delivery_line_type=delivery_line_type,
delivery_cell_type=delivery_cell_type,
delivery_list=delivery_list,
reindexable_movement_list=reindexable_movement_list, **kw)
def resourceGroupProcessing(resource_group, delivery, delivery_type, delivery_line_type, delivery_cell_type, delivery_list, reindexable_movement_list, delivery_module=None, default_rule_id=None, **kw):
if default_rule_id == 'default_amortisation_rule':
resource = resource_group.resource
for date_group in resource_group.group_list:
dateGroupProcessing(date_group=date_group,
path_group=None,
delivery_module=delivery_module,
delivery_type=delivery_type,
delivery_line_type=delivery_line_type,
delivery_cell_type=delivery_cell_type,
order=None,
delivery_list=delivery_list,
reindexable_movement_list=reindexable_movement_list,
default_rule_id=default_rule_id,
resource=resource)
else:
if delivery_type == 'Production Report': if delivery_type == 'Production Report':
if resource_group.resource.find('operation') == 0: if resource_group.resource.find('operation') == 0:
delivery_line_type = 'Production Report Operation' delivery_line_type = 'Production Report Operation'
...@@ -669,7 +822,6 @@ class SimulationTool (Folder, UniqueObject): ...@@ -669,7 +822,6 @@ class SimulationTool (Folder, UniqueObject):
resource = resource_group.resource, resource = resource_group.resource,
) )
delivery_line = delivery[new_delivery_line_id] delivery_line = delivery[new_delivery_line_id]
#LOG('Ligne cre',0,str(delivery_line.getId())+' '+str(delivery_line.getResource()))
line_variation_category_list = [] line_variation_category_list = []
line_variation_base_category_dict = {} line_variation_base_category_dict = {}
...@@ -758,6 +910,52 @@ class SimulationTool (Folder, UniqueObject): ...@@ -758,6 +910,52 @@ class SimulationTool (Folder, UniqueObject):
force_update = 1, force_update = 1,
) )
delivery_list = []
reindexable_movement_list = []
if movement_group is not None:
# Verify the rule used to build the movements
default_rule_id = None
if len(movement_group.movement_list) > 0:
f = getattr(movement_group.movement_list[0], 'getRootAppliedRule', None)
if f is not None:
applied_rule = f()
default_rule_id = applied_rule.getSpecialiseId()
LOG('buildDeliveryList :', 0, 'default_rule = %s' % repr(default_rule_id))
if default_rule_id == 'default_amortisation_rule':
LOG('buildDeliveryList :', 0, 'default_rule is default_amortisation_rule')
delivery_module = self.getPortalObject().accounting
delivery_type = 'Amortisation Transaction'
delivery_line_type = delivery_type + ' Line'
delivery_cell_type = None
for resource_group in movement_group.group_list:
resourceGroupProcessing(resource_group=resource_group,
delivery=None,
delivery_module=delivery_module,
delivery_type=delivery_type,
delivery_line_type=delivery_line_type,
delivery_cell_type=delivery_cell_type,
delivery_list=delivery_list,
reindexable_movement_list=reindexable_movement_list,
default_rule_id=default_rule_id)
for movement in movement_group.movement_list:
movement.immediateReindexObject()
else:
for order_group in movement_group.group_list:
if orderGroupProcessing(order_group=order_group,
delivery_list=delivery_list,
reindexable_movement_list=reindexable_movement_list) == -1:
return delivery_list
# If we reach this point, it means we could # If we reach this point, it means we could
# create deliveries # create deliveries
# get_transaction().commit() # get_transaction().commit()
......
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