Commit c9a2fc29 authored by Romain Courteaud's avatar Romain Courteaud

Remove workflow methods.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2809 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6a2427fd
##############################################################################
#
# 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
......@@ -40,10 +41,8 @@ class Order(Delivery):
# CMF Type Definition
meta_type = 'ERP5 Order'
portal_type = 'Order'
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
isDelivery = 1
isAccountable = 0
# Declarative security
security = ClassSecurityInfo()
......@@ -58,21 +57,18 @@ class Order(Delivery):
, PropertySheet.Arrow
, PropertySheet.Reference
, PropertySheet.TradeCondition
, PropertySheet.PaymentCondition
, PropertySheet.Comment
, PropertySheet.Order
)
security.declarePrivate( '_edit' )
def _edit(self, REQUEST=None, force_update = 0, **kw):
Delivery._edit(self, REQUEST=REQUEST, force_update = force_update, **kw)
# We must expand our applied rule only if not confirmed
if self.getSimulationState() in self.getPortalPlannedOrderStateList():
self.updateAppliedRule() # This should be implemented with the interaction tool rather than with this hard coding
def updateAppliedRule(self):
if self.getSimulationState() not in self.getPortalDraftOrderStateList():
# Nothing to do
self._createOrderRule()
security.declareProtected(Permissions.AccessContentsInformation, 'isAccountable')
security.declareProtected(Permissions.AccessContentsInformation, \
'isAccountable')
def isAccountable(self):
"""
Returns 1 if this needs to be accounted
......@@ -84,21 +80,25 @@ class Order(Delivery):
def _createOrderRule(self):
# Return if draft or cancelled simulation_state
if self.getSimulationState() in ('cancelled',):
# The applied rule should be cleaned up ie. empty all movements which have
# no confirmed children
# The applied rule should be cleaned up ie. empty all movements
# which have no confirmed children
return
# Otherwise, expand
# Look up if existing applied rule
my_applied_rule_list = self.getCausalityRelatedValueList(portal_type='Applied Rule')
my_applied_rule_list = \
self.getCausalityRelatedValueList(portal_type='Applied Rule')
LOG('Order._createOrderRule,my_applied_rule_list',0,my_applied_rule_list)
if len(my_applied_rule_list) == 0:
# Create a new applied order rule (portal_rules.order_rule)
portal_rules = getToolByName(self, 'portal_rules')
portal_simulation = getToolByName(self, 'portal_simulation')
my_applied_rule = portal_rules.default_order_rule.constructNewAppliedRule(portal_simulation)
my_applied_rule = \
portal_rules.default_order_rule.constructNewAppliedRule( \
portal_simulation)
# Set causality
my_applied_rule.setCausalityValue(self)
my_applied_rule.flushActivity(invoke = 1) # We must make sure this rule is indexed
# XXX my_applied_rule.flushActivity(invoke = 1)
# We must make sure this rule is indexed
# now in order not to create another one later
elif len(my_applied_rule_list) == 1:
# Re expand the rule if possible
......@@ -112,69 +112,22 @@ class Order(Delivery):
# We are now certain we have a single applied rule
# It is time to expand it
LOG('Order._createOrderRule,my_applied_rule.getPhysicalPath()',0,my_applied_rule.getPhysicalPath())
LOG('Order._createOrderRule,my_applied_rule.getPhysicalPath()',0, \
my_applied_rule.getPhysicalPath())
self.activate().expand(my_applied_rule.getId())
security.declareProtected(Permissions.ModifyPortalContent, 'autoPlan')
def _autoPlan(self):
"""
Sets the order to auto_planned. The auto_plan state
is used to differentiate planned orders generated by
the planification system with planned orders depending
of a user decision
"""
# self._createOrderRule()
# No simulation created at this point
autoPlan = WorkflowMethod(_autoPlan, id='auto_plan')
security.declareProtected(Permissions.ModifyPortalContent, 'plan')
def _plan(self):
"""
Sets the order to planned
"""
self._createOrderRule()
plan = WorkflowMethod(_plan, id='plan')
security.declareProtected(Permissions.ModifyPortalContent, 'order')
def _order(self):
"""
Sets the order to ordered
"""
# make sure it is planned
# then plan order simulation
self._createOrderRule()
order = WorkflowMethod(_order, id='order')
security.declareProtected(Permissions.ModifyPortalContent, 'confirm')
def _confirm(self):
"""
Sets the order to ordered
(a Workflow Script is responsible of creating the delivery)
Confirm is still not creating deliveries XXX - check activities seriously to make sure
they are not flushed in case of error
"""
LOG('Order._confirm starting... on',0,self.getPhysicalPath())
self._createOrderRule()
# At confirm stage, we create deliveries for this order
LOG('Order._confirm finished ._createOrderRule... on',0,self.getPhysicalPath())
self.activate(priority=4).buildDeliveryList()
LOG('Order._confirm finished activate of buildDeliveryList... on',0,self.getPhysicalPath())
confirm = WorkflowMethod(_confirm, 'confirm')
security.declareProtected(Permissions.ModifyPortalContent, 'buildDeliveryList')
security.declareProtected(Permissions.ModifyPortalContent, \
'buildDeliveryList')
def buildDeliveryList(self):
# Make sure there is exactly one applied rule
my_applied_rule_list = self.getCausalityRelatedValueList(portal_type='Applied Rule')
my_applied_rule_list = self.getCausalityRelatedValueList( \
portal_type='Applied Rule')
if len(my_applied_rule_list) != 1:
# Make sure we have an order rule
self._createOrderRule()
# Make sure there is exactly one applied rule
my_applied_rule_list = self.getCausalityRelatedValueList(portal_type='Applied Rule')
my_applied_rule_list = self.getCausalityRelatedValueList( \
portal_type='Applied Rule')
if len(my_applied_rule_list) != 1:
# XXX This is an error
raise CategoryError, "Order has no or too many order rule(s)"
......@@ -184,73 +137,69 @@ class Order(Delivery):
raise CategoryError, "Order has None order rule"
# Make sure applied rule has been reindexed
# Make sure there are no more activities on this order related to expand
self.flushActivity(invoke=0, method_id='expand') # Make sure expand is finished
self.flushActivity(invoke=0, method_id='expand')
# Make sure expand is finished
# We are expanding but are not allowed to if state wrong...
# (ex. confirmed)
applied_rule.expand(force = 1) # thus, we mist force expand of applied order rule
applied_rule.expand(force = 1)
# thus, we mist force expand of applied order rule
applied_rule.flushActivity(invoke=1)
# Build delivery list on applied rule
# Currently, we build it 'again' but we should actually only build
# deliveries for orphaned movements
if self.getPortalType() == 'Production Order' :
delivery_list = self.ProductionOrder_buildDeliveryList() # Coramy specific moved to portal_simulation
delivery_list = self.ProductionOrder_buildDeliveryList()
# Coramy specific moved to portal_simulation
#else:
elif self.getPortalType() in ('Purchase Order', 'Sale Order') :
delivery_list = self.Order_createPackingList() # Coramy specific should be moved to portal_simulation
#self.informDeliveryList(delivery_list=delivery_list, comment=repr(delivery_list)) # XXX Not ready
def _informDeliveryList(self, delivery_list=None, comment=None):
pass
informDeliveryList = WorkflowMethod(_informDeliveryList, id='informDeliveryList')
security.declareProtected(Permissions.ModifyPortalContent, 'cancel')
def cancel(self):
"""
Sets the order to ordered
"""
# No need to create an order rule
# Should actually delete form simulation XXX
self.activate().applyToOrderRelatedMovement(method_id = 'expand')
cancel = WorkflowMethod(cancel)
delivery_list = self.Order_createPackingList()
# Coramy specific should be moved to portal_simulation
#self.informDeliveryList(delivery_list=delivery_list,
# comment=repr(delivery_list)) # XXX Not ready
def applyToOrderRelatedMovement(self, portal_type='Simulation Movement', method_id = 'expand'):
def applyToOrderRelatedMovement(self, portal_type='Simulation Movement', \
method_id = 'expand'):
"""
Warning: does not work if it was not catalogued immediately
"""
for my_simulation_movement in self.getOrderRelatedValueList(
portal_type = 'Simulation Movement'):
portal_type='Simulation Movement'):
# And apply
getattr(my_simulation_movement, method_id)()
for m in self.contentValues(filter={'portal_type': self.getPortalMovementTypeList()}):
for m in self.contentValues(filter={'portal_type': \
self.getPortalMovementTypeList()}):
# Find related in simulation
for my_simulation_movement in m.getOrderRelatedValueList(
portal_type = 'Simulation Movement'):
portal_type='Simulation Movement'):
# And apply
getattr(my_simulation_movement, method_id)()
for c in m.contentValues(filter={'portal_type': 'Delivery Cell'}):
for my_simulation_movement in c.getOrderRelatedValueList(
portal_type = 'Simulation Movement'):
portal_type='Simulation Movement'):
# And apply
getattr(my_simulation_movement, method_id)()
def applyToOrderRelatedAppliedRule(self, method_id = 'expand'):
my_applied_rule = self.getCausalityRelatedValue(portal_type = 'Applied Rule')
def applyToOrderRelatedAppliedRule(self, method_id='expand'):
my_applied_rule = self.getCausalityRelatedValue( \
portal_type='Applied Rule')
getattr(my_applied_rule.getObject(), method_id)()
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderRelatedMovementList')
security.declareProtected(Permissions.AccessContentsInformation, \
'getOrderRelatedMovementList')
def getOrderRelatedMovementList(self):
"""
Returns simulation movements related to a cell or line of this order
Returns simulation movements related to a cell or line
of this order
"""
result = self.getOrderRelatedValueList( portal_type = 'Simulation Movement')
for m in self.contentValues(filter={'portal_type': self.getPortalMovementTypeList()}):
result = self.getOrderRelatedValueList(portal_type='Simulation Movement')
for m in self.contentValues(filter={'portal_type': \
self.getPortalMovementTypeList()}):
# Find related in simulation
result += m.getOrderRelatedValueList( portal_type = 'Simulation Movement')
result += m.getOrderRelatedValueList(portal_type='Simulation Movement')
for c in m.contentValues(filter={'portal_type': 'Delivery Cell'}):
result += c.getOrderRelatedValueList( portal_type = 'Simulation Movement')
result += c.getOrderRelatedValueList( \
portal_type='Simulation Movement')
return result
def reindexObject(self, *k, **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