Commit c14fa82b authored by Romain Courteaud's avatar Romain Courteaud

Clean up expand.

Remove factory type information.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3215 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 71f2c2fe
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002, 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# Romain Courteaud <romain@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
...@@ -42,9 +43,6 @@ class DeliveryRule(Rule): ...@@ -42,9 +43,6 @@ class DeliveryRule(Rule):
# CMF Type Definition # CMF Type Definition
meta_type = 'ERP5 Delivery Rule' meta_type = 'ERP5 Delivery Rule'
portal_type = 'Delivery Rule' portal_type = 'Delivery Rule'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -57,64 +55,13 @@ class DeliveryRule(Rule): ...@@ -57,64 +55,13 @@ class DeliveryRule(Rule):
, PropertySheet.DublinCore , PropertySheet.DublinCore
) )
# CMF Factory Type Information
factory_type_information = \
{ 'id' : portal_type
, 'meta_type' : meta_type
, 'description' : """\
An ERP5 Rule..."""
, 'icon' : 'rule_icon.gif'
, 'product' : 'ERP5'
, 'factory' : 'addDeliveryRule'
, 'immediate_view' : 'rule_view'
, 'allow_discussion' : 1
, 'allowed_content_types': ()
, 'filter_content_types' : 1
, 'global_allow' : 1
, 'actions' :
( { 'id' : 'view'
, 'name' : 'View'
, 'category' : 'object_view'
, 'action' : 'rule_view'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'list'
, 'name' : 'Object Contents'
, 'category' : 'object_action'
, 'action' : 'folder_contents'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'print'
, 'name' : 'Print'
, 'category' : 'object_print'
, 'action' : 'rule_print'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'metadata'
, 'name' : 'Metadata'
, 'category' : 'object_view'
, 'action' : 'metadata_edit'
, 'permissions' : (
Permissions.View, )
}
, { 'id' : 'translate'
, 'name' : 'Translate'
, 'category' : 'object_action'
, 'action' : 'translation_template_view'
, 'permissions' : (
Permissions.TranslateContent, )
}
)
}
def test(self, movement): def test(self, movement):
""" """
Tests if the rule (still) applies Tests if the rule (still) applies
""" """
# A deliveyr rule never applies since it is always explicitely instanciated # A delivery rule never applies
# since it is always explicitely instanciated
return 0 return 0
# Simulation workflow # Simulation workflow
...@@ -131,84 +78,75 @@ An ERP5 Rule...""" ...@@ -131,84 +78,75 @@ An ERP5 Rule..."""
delivery_line_type = 'Simulation Movement' delivery_line_type = 'Simulation Movement'
# Get the delivery when we come from # Get the delivery when we come from
my_delivery = applied_rule.getDefaultCausalityValue() # Causality is a kind of Delivery (ex. Packing List) # Causality is a kind of Delivery (ex. Packing List)
my_delivery = applied_rule.getDefaultCausalityValue()
# Only expand if my_delivery is not None and state is not 'confirmed' # Only expand if my_delivery is not None
# and state is not 'confirmed'
if my_delivery is not None: if my_delivery is not None:
#if my_delivery.getSimulationState() not in ('delivered', ): #if my_delivery.getSimulationState() not in ('delivered', ):
# Even if delivered, we should always calculate consequences # Even if delivered, we should always calculate consequences
if 1:
# First, check each contained movement and make # First, check each contained movement and make
# 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 = []
for movement in applied_rule.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}): for movement in applied_rule.contentValues(
delivery_value = movement.getDeliveryValue(portal_type=applied_rule.getPortalOrderMovementTypeList()) filter={'portal_type':applied_rule.getPortalMovementTypeList()}):
if delivery_value is None: delivery_value = movement.getDeliveryValue(
movement.flushActivity(invoke=0) portal_type=applied_rule.getPortalOrderMovementTypeList())
applied_rule._delObject(movement.getId()) # XXXX Make sure this is not deleted if already in delivery
need_to_delete_movement = 0
if delivery_value is None:
need_to_delete_movement = 1
else:
if delivery_value.hasCellContent():
need_to_delete_movement = 1
else: else:
if getattr(delivery_value, 'isCell', 0): if len(delivery_value.getDeliveryRelatedValueList()) > 1:
if len(delivery_value.getDeliveryRelatedValueList()) > 1: need_to_delete_movement = 1
# Our delivery_value is already related to another simulation movement
# Delete ourselve
movement.flushActivity(invoke=0)
applied_rule._delObject(movement.getId()) # XXXX Make sure this is not deleted if already in delivery
else:
existing_uid_list += [delivery_value.getUid()]
elif delivery_value.hasCellContent():
# Do not keep head of cells
delivery_value.flushActivity(invoke=0)
applied_rule._delObject(movement.getId()) # XXXX Make sure this is not deleted if already in delivery
else: else:
if len(delivery_value.getDeliveryRelatedValueList()) > 1: existing_uid_list += [delivery_value.getUid()]
# Our delivery_value is already related to another simulation movement
# Delete ourselve if need_to_delete_movement:
movement.flushActivity(invoke=0) # Our delivery_value is already related
applied_rule._delObject(movement.getId()) # XXXX Make sure this is not deleted if already in delivery # to another simulation movement
# Delete ourselve
# movement.flushActivity(invoke=0)
# XXX Make sure this is not deleted if already in delivery
applied_rule._delObject(movement.getId())
# Copy each movement (line or cell) from the delivery is that
for delivery_movement in my_delivery.getMovementList():
try:
if len(delivery_movement.getDeliveryRelatedValueList()) == 0:
# Only create if orphaned movement
if delivery_movement.getUid() not in existing_uid_list:
# Generate a nicer ID
if delivery_movement.getParentUid() ==\
delivery_movement.getExplanationUid():
# We are on a line
new_id = delivery_movement.getId()
else: else:
existing_uid_list += [delivery_value.getUid()] # On a cell
new_id = "%s_%s" % (delivery_movement.getParentId(),
# Copy each movement (line or cell) from the delivery is that delivery_movement.getId())
for delivery_line_object in my_delivery.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}): # Generate the simulation movement
try: new_sim_mvt = applied_rule.newContent(
if delivery_line_object.hasCellContent(): type_name=delivery_line_type,
for c in delivery_line_object.getCellValueList(): id=new_id,
if len(c.getDeliveryRelatedValueList()) == 0: # Only create if orphaned movement order_value=delivery_movement,
if c.getUid() not in existing_uid_list: delivery_value=delivery_movement,
new_id = delivery_line_object.getId() + '_' + c.getId() # XXX Do we need to copy the quantity
my_delivery.portal_types.constructContent(type_name=delivery_line_type, # Why not the resource, the variation,...
container=applied_rule, quantity=delivery_movement.getQuantity(),
id=new_id, delivery_ratio=1,
delivery_value = c, deliverable=1)
order_value = c, except AttributeError:
quantity = c.getQuantity(), LOG('ERP5: WARNING', 0,
start_date = c.getStartDate(), 'AttributeError during expand on delivery line %s'\
stop_date = c.getStopDate(), % delivery_line_object.absolute_url())
deliverable = 1
)
# We must create both order and delivery link in this case
# since our simulation model is based on order and delivery
my_delivery.flushActivity(invoke=1) # Flush since we may need immediately getDeliveryRelatedValueList
else:
if len(delivery_line_object.getDeliveryRelatedValueList()) == 0: # Only create if orphaned movement
if delivery_line_object.getUid() not in existing_uid_list:
new_id = delivery_line_object.getId()
my_delivery.portal_types.constructContent(type_name=delivery_line_type,
container=applied_rule,
id=new_id,
delivery_value = delivery_line_object,
order_value = delivery_line_object,
quantity = delivery_line_object.getQuantity(),
start_date = delivery_line_object.getStartDate(),
stop_date = delivery_line_object.getStopDate(),
deliverable = 1
)
# Source, Destination, Quantity, Date, etc. are
# acquired from the delivery line and need not to be copied.
except AttributeError:
LOG('ERP5: WARNING', 0, 'AttributeError during expand on delivery line %s'
% delivery_line_object.absolute_url())
# Pass to base class # Pass to base class
Rule.expand(self, applied_rule, **kw) Rule.expand(self, applied_rule, **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