Commit 4d45efbb authored by Romain Courteaud's avatar Romain Courteaud

Clean up expand.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3281 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 51a2ac3f
...@@ -91,31 +91,27 @@ class DeliveryRule(Rule): ...@@ -91,31 +91,27 @@ class DeliveryRule(Rule):
# a list of delivery ids which do not need to be copied # a list of delivery ids which do not need to be copied
# eventually delete movement which do not exist anylonger # eventually delete movement which do not exist anylonger
existing_uid_list = [] existing_uid_list = []
existing_uid_list_append = existing_uid_list.append
movement_type_list = applied_rule.getPortalMovementTypeList()
order_movement_type_list = \
applied_rule.getPortalOrderMovementTypeList()
for movement in applied_rule.contentValues( for movement in applied_rule.contentValues(
filter={'portal_type':applied_rule.getPortalMovementTypeList()}): filter={'portal_type':movement_type_list}):
delivery_value = movement.getDeliveryValue( delivery_value = movement.getDeliveryValue(
portal_type=applied_rule.getPortalOrderMovementTypeList()) portal_type=order_movement_type_list)
need_to_delete_movement = 0
if delivery_value is None: if (delivery_value is None) or\
need_to_delete_movement = 1 (delivery_value.hasCellContent()) or\
else: (len(delivery_value.getDeliveryRelatedValueList()) > 1):
if delivery_value.hasCellContent():
need_to_delete_movement = 1
else:
if len(delivery_value.getDeliveryRelatedValueList()) > 1:
need_to_delete_movement = 1
else:
existing_uid_list += [delivery_value.getUid()]
if need_to_delete_movement:
# Our delivery_value is already related # Our delivery_value is already related
# to another simulation movement # to another simulation movement
# Delete ourselve # Delete ourselve
# movement.flushActivity(invoke=0) # movement.flushActivity(invoke=0)
# XXX Make sure this is not deleted if already in delivery # XXX Make sure this is not deleted if already in delivery
applied_rule._delObject(movement.getId()) applied_rule._delObject(movement.getId())
else:
existing_uid_list_append(delivery_value.getUid())
# Copy each movement (line or cell) from the delivery is that # Copy each movement (line or cell) from the delivery is that
for delivery_movement in my_delivery.getMovementList(): for delivery_movement in my_delivery.getMovementList():
......
...@@ -85,93 +85,57 @@ class OrderRule(Rule): ...@@ -85,93 +85,57 @@ class OrderRule(Rule):
# with the fact that once simulation is launched, we stick to it) # with the fact that once simulation is launched, we stick to it)
state = applied_rule.getLastExpandSimulationState() state = applied_rule.getLastExpandSimulationState()
if force or \ if force or \
(state not in \ (state not in applied_rule.getPortalReservedInventoryStateList()\
applied_rule.getPortalReservedInventoryStateList() and \ and state not in applied_rule.getPortalCurrentInventoryStateList()):
state not in \
applied_rule.getPortalCurrentInventoryStateList()):
# First, check each contained movement and make # First, check each contained movement and make
# a list of order ids which do not need to be copied # a list of order ids which do not need to be copied
# eventually delete movement which do not exist anylonger # eventually delete movement which do not exist anylonger
existing_uid_list = [] existing_uid_list = []
append = existing_uid_list.append existing_uid_list_append = existing_uid_list.append
movement_type_list = applied_rule.getPortalMovementTypeList() movement_type_list = applied_rule.getPortalMovementTypeList()
for movement in applied_rule.contentValues(filter={'portal_type': \ order_movement_type_list = \
movement_type_list}): applied_rule.getPortalOrderMovementTypeList()
for movement in applied_rule.contentValues(
filter={'portal_type': movement_type_list}):
order_value = movement.getOrderValue(\ order_value = movement.getOrderValue(\
portal_type=movement_type_list) portal_type=order_movement_type_list)
if order_value is None:
movement.flushActivity(invoke=0) if (order_value is None) or\
(order_value.hasCellContent()):
# XXX Make sure this is not deleted if already in delivery
applied_rule._delObject(movement.getId()) applied_rule._delObject(movement.getId())
# XXX Make sur this is not deleted if already in delivery
else: else:
if getattr(order_value, 'isCell', 0): existing_uid_list_append(order_value.getUid())
append(order_value.getUid())
elif order_value.hasCellContent(): for order_movement in my_order.getMovementList():
# Do not keep head of cells
LOG('INFO', 0, 'Order Rule Deleting Simulatino Movement %s' \
% movement.getRelativeUrl())
order_value.flushActivity(invoke=0)
applied_rule._delObject(movement.getId())
# XXX Make sur this is not deleted if already in delivery
else:
append(order_value.getUid())
# Copy each movement (line or cell) from the order
for order_line_object in my_order.contentValues(filter={ \
'portal_type':movement_type_list}):
LOG('OrderRule.expand, examining:',0, \
order_line_object.getPhysicalPath())
try: try:
if order_line_object.hasCellContent(): if order_movement.getUid() not in existing_uid_list:
for c in order_line_object.getCellValueList(): # Generate a nicer ID
LOG('Cell in', 0, '%s %s' % (c.getUid(), existing_uid_list)) if order_movement.getParentUid() ==\
if c.getUid() not in existing_uid_list: order_movement.getExplanationUid():
new_id = order_line_object.getId() + '_' + c.getId() # We are on a line
LOG('Create Cell', 0, str(new_id)) new_id = order_movement.getId()
new_line = applied_rule.newContent( else:
type_name=delivery_line_type, # On a cell
id=new_id, new_id = "%s_%s" % (order_movement.getParentId(),
order_value = c, order_movement.getId())
quantity = c.getQuantity(),
# source = c.getSource(), # Generate the simulation movement
# destination = c.getDestination(), # Source, Destination, Quantity, Date, etc. are
# source_section = c.getSourceSection(), # acquired from the order and need not to be copied.
# destination_section = c.getDestinationSection(), new_sim_mvt = applied_rule.newContent(
deliverable = 1 type_name=delivery_line_type,
) id=new_id,
LOG('OrderRule.expand, object created:',0, \ order_value=order_movement,
new_line.getPhysicalPath()) quantity=order_movement.getQuantity(),
#LOG('After Create Cell', 0, str(new_id)) delivery_ratio=1,
else: # No acquisition on variation_category_list
if order_line_object.getUid() not in existing_uid_list: # in this case to prevent user failure
new_id = order_line_object.getId() variation_category_list = \
LOG('Line', 0, str(new_id)) order_movement.getVariationCategoryList(),
if order_line_object.getVariationCategoryList() == []: deliverable=1)
new_line = applied_rule.newContent(
type_name=delivery_line_type,
container=applied_rule,
id=new_id,
order_value = order_line_object,
quantity = order_line_object.getQuantity(),
# No acquisition on variation_category_list in this case,
# to prevent user failure
variation_category_list = [],
# source = order_line_object.getSource(),
# destination = order_line_object.getDestination(),
# source_section = order_line_object.getSourceSection(),
# destination_section = \
# order_line_object.getDestinationSection(),
deliverable = 1
)
LOG('OrderRule.expand, object created:',0, \
new_line.getPhysicalPath())
LOG('After Create Cell', 0, str(new_id))
# Source, Destination, Quantity, Date, etc. are
# acquired from the order and need not to be copied.
else:
raise 'Error', 'VariationCategoryList is defined on\
OrderLine %s and no cell exists.' %\
order_line_object.getRelativeUrl()
except AttributeError: except AttributeError:
LOG('ERP5: WARNING', 0, \ LOG('ERP5: WARNING', 0, \
'AttributeError during expand on order line %s' \ 'AttributeError during expand on order line %s' \
...@@ -179,8 +143,8 @@ class OrderRule(Rule): ...@@ -179,8 +143,8 @@ class OrderRule(Rule):
# Now we can set the last expand simulation state # Now we can set the last expand simulation state
# to the current state # to the current state
applied_rule.setLastExpandSimulationState( \ applied_rule.setLastExpandSimulationState(\
my_order.getSimulationState()) my_order.getSimulationState())
# Pass to base class # Pass to base class
Rule.expand(self, applied_rule, force=force, **kw) Rule.expand(self, applied_rule, force=force, **kw)
......
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