Commit 4877945b authored by Tatuya Kamada's avatar Tatuya Kamada

Merge branch 'arnau-RD-ERP5ify-portal_workflow' into ERP5ify-portal_workfow_yusei_20210303

parents c8232258 2a7ec09f
......@@ -32,15 +32,14 @@ def dumpWorkflowChain(self, ignore_default=False,
if title == id_:
title = None
chain = None
if cbt is not None and cbt.has_key(id_):
cbt_list = [x for x in cbt[id_] if not(x in ignore_id_set)]
if keep_order:
cbt_list = [x for x in t.getTypeWorkflowList() if not(x in ignore_id_set)]
if not cbt_list:
if not(ignore_default):
chain = ['(Default)']
elif keep_order:
chain = cbt_list
else:
chain = sorted(cbt_list)
else:
if not(ignore_default):
chain = ['(Default)']
if chain:
types_info.append({'id': id_,
'title': title,
......
......@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo
from Persistence import PersistentMapping
from Acquisition import aq_base
from Products.ERP5Type import Permissions, PropertySheet
from zLOG import LOG, ERROR
from erp5.component.tool.ConfiguratorTool import _validateFormToRequest
from erp5.component.document.Item import Item
......@@ -56,8 +57,8 @@ def initializeDocument(workflow, document):
status_dict = {state_bc_id: workflow.getSource()}
variable_list = workflow.contentValues(portal_type='Workflow Variable')
for variable in variable_list:
status_dict[variable.getTitle()] = variable.getVariableValue(object=object)
workflow._updateWorkflowHistory(document, status_dict)
status_dict[variable.getTitle()] = variable.getVariableDefaultExpression(object=object)
_updateWorkflowHistory(document, status_dict)
def _generateHistoryKey(workflow):
"""
Generate a key used in the workflow history.
......@@ -80,6 +81,46 @@ def getWorkflowHistory(state, document, remove_undo=0, remove_not_displayed=0):
else:
result.append(x.copy())
return result
def _updateWorkflowHistory(workflow, document, status_dict):
"""
Change the state of the object.
"""
if workflow.getPortalType() in ('Interaction Workflow', 'InteractionWorkflowDefinition'):
return
# Create history attributes if needed
if getattr(aq_base(document), 'workflow_history', None) is None:
document.workflow_history = PersistentMapping()
# XXX this _p_changed is apparently not necessary
document._p_changed = 1
# Add an entry for the workflow in the history
workflow_key = workflow.getReference()
if not document.workflow_history.has_key(workflow_key):
document.workflow_history[workflow_key] = ()
# Update history
document.workflow_history[workflow_key] += (status_dict,)
# XXX this _p_changed marks the document modified, but only the
# PersistentMapping is modified
# document._p_changed = 1
# XXX this _p_changed is apparently not necessary
#document.workflow_history._p_changed = 1
def undoTransition(state, document):
"""
Reverse previous transition
"""
wh = getWorkflowHistory(state, document, remove_undo=1)
status_dict = wh[-2]
# Update workflow state
state_bc_id = state.getParentValue().getStateBaseCategory()
document.setCategoryMembership(state_bc_id, status_dict[state_bc_id])
# Update workflow history
status_dict['undo'] = 1
_updateWorkflowHistory(state.getParentValue(), document, status_dict)
# XXX
LOG("State, undo", ERROR, "Variable (like DateTime) need to be updated!")
def _checkPermission(transition, document):
"""
Check if transition is allowed.
......@@ -104,6 +145,90 @@ def getAvailableTransitionList(state, document):
if value:
result_list.append(transition)
return result_list
class StateError(Exception):
"""
Must call only an available transition
"""
pass
def executeTransition(state, transition, document, form_kw=None):
"""
Execute transition on the object.
"""
if transition not in getAvailableTransitionList(state, document):
raise StateError
else:
execute(transition, document, form_kw=form_kw)
def _executeBeforeScript(self, document, form_kw=None):
"""
Execute pre transition script.
"""
if form_kw is None:
form_kw = {}
script_id = getattr(self.aq_base, 'before_script_id', None)
if script_id is not None:
script = getattr(document, script_id)
script(**form_kw)
def _changeState(self, document):
"""
Change the state of the object.
"""
state = self.getDestination()
if state is not None:
# Some transitions don't update the state
state_bc_id = self.getParentValue().getStateBaseCategory()
document.setCategoryMembership(state_bc_id, state)
def _executeAfterScript(self, document, form_kw=None):
"""
Execute post transition script.
"""
if form_kw is None:
form_kw = {}
script_id = getattr(self.aq_base, 'after_script_id', None)
if script_id is not None:
script = getattr(document, script_id)
script(**form_kw)
def execute(self, document, form_kw=None):
"""
Execute transition.
"""
workflow = self.getParentValue()
# Call the before script
_executeBeforeScript(self, document)
# Modify the state
_changeState(self, document)
# Get variable values
status_dict = workflow.getCurrentStatusDict(document)
status_dict['undo'] = 0
# Modify workflow history
state_bc_id = workflow.getStateBaseCategory()
state_object = document.unrestrictedTraverse(document.getCategoryMembershipList(state_bc_id)[0])
status_dict[state_bc_id] = state_object.getReference()
object_ = workflow.getStateChangeInformation(document, state_object, transition=self)
# Update all variables
for variable in workflow.contentValues(portal_type='Variable'):
if variable.getAutomaticUpdate():
# if we have it in form get it from there
# otherwise use default
variable_title = variable.getTitle()
if variable_title in form_kw:
status_dict[variable_title] = form_kw[variable_title]
else:
status_dict[variable_title] = variable.getInitialValue(object=object_)
# Update all transition variables
if form_kw is not None:
object_.REQUEST.other.update(form_kw)
for variable in self.contentValues(portal_type='Transition Variable'):
status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object_)
_updateWorkflowHistory(workflow, document, status_dict)
# Call the after script
_executeAfterScript(self, document, form_kw=form_kw)
class BusinessConfiguration(Item):
"""
......@@ -157,11 +282,11 @@ class BusinessConfiguration(Item):
def initializeWorkflow(self):
""" Initialize Related Workflow"""
workflow = self.getResourceValue()
workflow_history = getattr(self, 'workflow_history', {})
if workflow is None:
return
if self.getResource() not in workflow_history:
workflow_history = getattr(self, 'workflow_history', {})
if workflow.getReference() not in workflow_history:
if len(self.objectValues("ERP5 Configuration Save")) > 0:
raise ValueError("Business Configuration Cannot be initialized, \
it contains one or more Configurator Save")
......@@ -224,7 +349,7 @@ class BusinessConfiguration(Item):
## Add some variables so we can get use them in workflow after scripts
form_kw['configuration_save_url'] = configuration_save.getRelativeUrl()
form_kw['transition'] = transition.getRelativeUrl()
current_state.executeTransition(transition, self, form_kw=form_kw)
executeTransition(current_state, transition, self, form_kw=form_kw)
security.declarePrivate('_displayNextForm')
def _displayNextForm(self, \
......@@ -319,7 +444,7 @@ class BusinessConfiguration(Item):
for wh in workflow_history:
## go one step back
current_state = self.getCurrentStateValue()
current_state.undoTransition(self)
undoTransition(current_state, self)
if not wh['transition']:
raise ValueError("Empty URL for transition in workflow history.")
transition = self.unrestrictedTraverse(wh['transition'])
......@@ -343,18 +468,21 @@ class BusinessConfiguration(Item):
current_state = self.getCurrentStateValue()
transition = self.getNextTransition()
next_state = self.unrestrictedTraverse(transition.getDestination())
workflow = current_state.getParentValue()
for wh in getWorkflowHistory(current_state, self):
if next_state == self.unrestrictedTraverse(wh['current_state']):
if next_state == workflow.getStateValueById(wh['current_state']):
configuration_save = self.unrestrictedTraverse(wh['configuration_save_url'])
return configuration_save
security.declarePrivate('_isAlreadyConfSaveInWorkflowHistory')
def _isAlreadyConfSaveInWorkflowHistory(self, transition):
""" check if we have an entry in worklow history for this state """
workflow_history = getWorkflowHistory(self.getCurrentStateValue(), self, remove_undo=1)
current_state = self.getCurrentStateValue()
workflow = current_state.getParentValue()
workflow_history = getWorkflowHistory(current_state, self, remove_undo=1)
workflow_history.reverse()
for wh in workflow_history:
wh_state = self.unrestrictedTraverse(wh['current_state'])
wh_state = workflow.getStateValueById(wh['current_state'])
for wh_transition in getAvailableTransitionList(wh_state, self):
if wh_transition.getTransitionFormId() is not None and \
wh_transition != transition:
......
......@@ -143,7 +143,6 @@ class ConfiguratorTool(BaseTool):
response = {}
business_configuration.initializeWorkflow()
## initial state no previous form to validate
if business_configuration.isInitialConfigurationState():
need_validation = 0
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_displayEBusinessLotseDownload</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupCustomerBT5</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupStandardBT5</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_displayMaxmaDemoDownload</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupCustomerBT5</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupMaxmaDemoStandardBT5</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupRunMyDocPreferences</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupRunMyDocOrganisation</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupRunMyDocList</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupRunMyDocUserNumber</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupCustomerBT5</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupRunMyDocStandardBT5</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupAccounting</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_configureCategories</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupPreferences</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_configureConsultingOrganisation</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_configurePortalTypeRoles</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupEmployeeList</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupEmployeesNumber</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_displayDownload</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupCustomerBT5</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupStandardBT5</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupAccounting</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupPreferences</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupOrganisation</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupEmployeeList</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupEmployeesNumber</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_displayDownload</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupStandardCategory</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupCustomerBT5</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupPortalTypeRole</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupStandardBT5</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,10 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupCustomerBT5</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -23,6 +23,16 @@
</tuple>
</value>
</item>
<item>
<key> <string>after_script_id</string> </key>
<value> <string>BusinessConfiguration_setupOfficeJSDevelopmentStandardBT5</string> </value>
</item>
<item>
<key> <string>before_script_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......
......@@ -150,13 +150,6 @@ class InteractionWorkflow(Workflow):
def getValidRoleList(self):
return sorted(self.getPortalObject().acl_users.valid_roles())
security.declarePrivate('_updateWorkflowHistory')
def _updateWorkflowHistory(self, document, status_dict):
"""
Stateless.
"""
return
security.declarePrivate('getinteraction_workflowVariableMatchDict')
def getWorklistVariableMatchDict(self, info, check_guard=True):
return None
......
......@@ -34,12 +34,6 @@ from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5Type.XMLObject import XMLObject
class StateError(Exception):
"""
Must call only an available transition
"""
pass
class CustomStorageMatrixMixin(XMLMatrix):
"""
Prototype of a mixin allowing to have custom storage for matrix
......
......@@ -167,29 +167,6 @@ class Workflow(XMLObject):
except (ObjectDeleted,ObjectMoved):
pass
def _updateWorkflowHistory(self, document, status_dict):
"""
Change the state of the object.
"""
# Create history attributes if needed
if getattr(aq_base(document), 'workflow_history', None) is None:
document.workflow_history = PersistentMapping()
# XXX this _p_changed is apparently not necessary
document._p_changed = 1
# Add an entry for the workflow in the history
workflow_key = self.getReference()
if not document.workflow_history.has_key(workflow_key):
document.workflow_history[workflow_key] = ()
# Update history
document.workflow_history[workflow_key] += (status_dict,)
# XXX this _p_changed marks the document modified, but only the
# PersistentMapping is modified
# document._p_changed = 1
# XXX this _p_changed is apparently not necessary
#document.workflow_history._p_changed = 1
security.declarePublic('getDateTime')
def getDateTime(self):
"""
......
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