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,83 +78,74 @@ An ERP5 Rule...""" ...@@ -131,83 +78,74 @@ 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()}):
delivery_value = movement.getDeliveryValue(
portal_type=applied_rule.getPortalOrderMovementTypeList())
need_to_delete_movement = 0
if delivery_value is None: if delivery_value is None:
movement.flushActivity(invoke=0) need_to_delete_movement = 1
applied_rule._delObject(movement.getId()) # XXXX Make sure this is not deleted if already in delivery
else:
if getattr(delivery_value, 'isCell', 0):
if len(delivery_value.getDeliveryRelatedValueList()) > 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: else:
existing_uid_list += [delivery_value.getUid()] if delivery_value.hasCellContent():
elif delivery_value.hasCellContent(): need_to_delete_movement = 1
# 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: if len(delivery_value.getDeliveryRelatedValueList()) > 1:
# Our delivery_value is already related to another simulation movement need_to_delete_movement = 1
# Delete ourselve
movement.flushActivity(invoke=0)
applied_rule._delObject(movement.getId()) # XXXX Make sure this is not deleted if already in delivery
else: else:
existing_uid_list += [delivery_value.getUid()] existing_uid_list += [delivery_value.getUid()]
if need_to_delete_movement:
# Our delivery_value is already related
# 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 # Copy each movement (line or cell) from the delivery is that
for delivery_line_object in my_delivery.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}): for delivery_movement in my_delivery.getMovementList():
try: try:
if delivery_line_object.hasCellContent(): if len(delivery_movement.getDeliveryRelatedValueList()) == 0:
for c in delivery_line_object.getCellValueList(): # Only create if orphaned movement
if len(c.getDeliveryRelatedValueList()) == 0: # Only create if orphaned movement if delivery_movement.getUid() not in existing_uid_list:
if c.getUid() not in existing_uid_list: # Generate a nicer ID
new_id = delivery_line_object.getId() + '_' + c.getId() if delivery_movement.getParentUid() ==\
my_delivery.portal_types.constructContent(type_name=delivery_line_type, delivery_movement.getExplanationUid():
container=applied_rule, # We are on a line
id=new_id, new_id = delivery_movement.getId()
delivery_value = c,
order_value = c,
quantity = c.getQuantity(),
start_date = c.getStartDate(),
stop_date = c.getStopDate(),
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: else:
if len(delivery_line_object.getDeliveryRelatedValueList()) == 0: # Only create if orphaned movement # On a cell
if delivery_line_object.getUid() not in existing_uid_list: new_id = "%s_%s" % (delivery_movement.getParentId(),
new_id = delivery_line_object.getId() delivery_movement.getId())
my_delivery.portal_types.constructContent(type_name=delivery_line_type, # Generate the simulation movement
container=applied_rule, new_sim_mvt = applied_rule.newContent(
type_name=delivery_line_type,
id=new_id, id=new_id,
delivery_value = delivery_line_object, order_value=delivery_movement,
order_value = delivery_line_object, delivery_value=delivery_movement,
quantity = delivery_line_object.getQuantity(), # XXX Do we need to copy the quantity
start_date = delivery_line_object.getStartDate(), # Why not the resource, the variation,...
stop_date = delivery_line_object.getStopDate(), quantity=delivery_movement.getQuantity(),
deliverable = 1 delivery_ratio=1,
) deliverable=1)
# Source, Destination, Quantity, Date, etc. are
# acquired from the delivery line and need not to be copied.
except AttributeError: except AttributeError:
LOG('ERP5: WARNING', 0, 'AttributeError during expand on delivery line %s' LOG('ERP5: WARNING', 0,
'AttributeError during expand on delivery line %s'\
% delivery_line_object.absolute_url()) % delivery_line_object.absolute_url())
# Pass to base class # Pass to base class
......
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