Commit 30f37bb6 authored by iv's avatar iv

ERP5Workflow: fix and wip on categories

setting state category on workflow was overriding other catogories
(in particular the before/after script newly created)
parent 6ea012aa
......@@ -86,6 +86,23 @@ Most of the code in this file has been taken from patches/WorkflowTool.py.
_marker = [] # Create a new marker object.
def getERP5ScriptPath(erp5_workflow, dc_workflow, dc_script_name, category_name):
# XXX(WORKFLOW): remove hardcoded paths
if dc_script_name is not None:
script_path_base = category_name.strip('/') + '/' + 'portal_workflow/' + \
erp5_workflow.getId() + '/'
# check script is a Transition or a Script:
if dc_script_name in dc_workflow.transitions:
return(script_path_base + 'transition_' + dc_script_name)
elif dc_script_name in dc_workflow.scripts.objectIds():
# add a prefix if there is a conflict
if hasattr(erp5_workflow, dc_script_name):
return(script_path_base + 'ScriptPrefix_' + dc_script_name)
else:
return(script_path_base + dc_script_name)
return None
class WorkflowTool(BaseTool, OriginalWorkflowTool):
"""
A new container for DC workflow and workflow;
......@@ -283,7 +300,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
workflow.setDescription(dc_workflow.description)
if not is_temporary:
# create transitions
# create state and transitions (Workflow)
# or interactions (Interaction Workflow)
if workflow_type_id == 'DCWorkflowDefinition':
# remove default state and variables
for def_var in workflow.objectValues(portal_type='Workflow Variable'):
......@@ -305,26 +323,21 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
transition.setActboxName(tdef.actbox_name)
transition.setActboxUrl(tdef.actbox_url)
transition.setDescription(tdef.description)
if tdef.after_script_name is not None:
# check after script is a Transion or a Script:
if tdef.after_script_name in dc_workflow_transition_id_list:
transition.setAfterScriptId('transition_'+tdef.after_script_name)
elif tdef.after_script_name in dc_workflow.scripts.objectIds():
# add a prefix if there is a script & method conflict
if hasattr(workflow, tdef.after_script_name):
transition.setAfterScriptId('ScriptPrefix_'+tdef.after_script_name)
else:
transition.setAfterScriptId(tdef.after_script_name)
if tdef.script_name is not None:
# check before script is a Transion or a Script:
if tdef.script_name in dc_workflow_transition_id_list:
transition.setBeforeScriptId('transition_'+tdef.script_name)
elif tdef.script_name in dc_workflow.scripts.objectIds():
if hasattr(workflow, tdef.script_name):
# add a prefix if there is a script & method conflict
transition.setBeforeScriptId('ScriptPrefix_'+tdef.script_name)
else:
transition.setBeforeScriptId(tdef.script_name)
before_script_path = getERP5ScriptPath(workflow, dc_workflow,
tdef.script_name,
'before_script')
after_script_path = getERP5ScriptPath(workflow, dc_workflow,
tdef.after_script_name,
'after_script')
if before_script_path or after_script_path:
script_list = transition.getCategoryList()
if before_script_path:
script_list.append(before_script_path)
if after_script_path:
script_list.append(after_script_path)
transition.setCategoryList(script_list)
# configure guard
if tdef.guard:
transition.guard = tdef.guard
......@@ -376,7 +389,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# it's a remain in state transition.
continue
state_path = 'destination/' + '/'.join(state.getPath().split('/')[2:])
tdef.setCategoryList([state_path])
tdef.setCategoryList(tdef.getCategoryList() + [state_path])
# worklists (portal_type = Worklist)
for qid, qdef in dc_workflow.worklists.items():
worklist = workflow.newContent(portal_type='Worklist', temp_object=is_temporary)
......@@ -480,6 +493,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
interaction.setTriggerOncePerTransaction(tdef.once_per_transaction)
interaction.setTriggerType(tdef.trigger_type)
interaction.setDescription(tdef.description)
# create scripts (portal_type = Workflow Script)
dc_workflow_script_list = dc_workflow.scripts
for script_id in dc_workflow_script_list:
......
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