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>
# Romain Courteaud <romain@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
......@@ -42,9 +43,6 @@ class DeliveryRule(Rule):
# CMF Type Definition
meta_type = 'ERP5 Delivery Rule'
portal_type = 'Delivery Rule'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
# Declarative security
security = ClassSecurityInfo()
......@@ -57,64 +55,13 @@ class DeliveryRule(Rule):
, 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):
"""
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
# Simulation workflow
......@@ -131,83 +78,74 @@ An ERP5 Rule..."""
delivery_line_type = 'Simulation Movement'
# 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.getSimulationState() not in ('delivered', ):
# Even if delivered, we should always calculate consequences
if 1:
# First, check each contained movement and make
# a list of delivery ids which do not need to be copied
# eventually delete movement which do not exist anylonger
existing_uid_list = []
for movement in applied_rule.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}):
delivery_value = movement.getDeliveryValue(portal_type=applied_rule.getPortalOrderMovementTypeList())
for movement in applied_rule.contentValues(
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:
movement.flushActivity(invoke=0)
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
need_to_delete_movement = 1
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
if delivery_value.hasCellContent():
need_to_delete_movement = 1
else:
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
need_to_delete_movement = 1
else:
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
for delivery_line_object in my_delivery.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}):
for delivery_movement in my_delivery.getMovementList():
try:
if delivery_line_object.hasCellContent():
for c in delivery_line_object.getCellValueList():
if len(c.getDeliveryRelatedValueList()) == 0: # Only create if orphaned movement
if c.getUid() not in existing_uid_list:
new_id = delivery_line_object.getId() + '_' + c.getId()
my_delivery.portal_types.constructContent(type_name=delivery_line_type,
container=applied_rule,
id=new_id,
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
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:
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,
# On a cell
new_id = "%s_%s" % (delivery_movement.getParentId(),
delivery_movement.getId())
# Generate the simulation movement
new_sim_mvt = applied_rule.newContent(
type_name=delivery_line_type,
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.
order_value=delivery_movement,
delivery_value=delivery_movement,
# XXX Do we need to copy the quantity
# Why not the resource, the variation,...
quantity=delivery_movement.getQuantity(),
delivery_ratio=1,
deliverable=1)
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())
# 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