Commit 19033e94 authored by Jérome Perrin's avatar Jérome Perrin

graph_editor: more robust BusinessProcess_getGraph

 - use relative url as key, not id/reference as it's not unique enough
 - support business link using non existent trade state ( for missing
paths in business template)
parent d181977c
...@@ -18,7 +18,7 @@ def getBusinessProcessGraph(business_process): ...@@ -18,7 +18,7 @@ def getBusinessProcessGraph(business_process):
for trade_state in portal.portal_categories.trade_state.getCategoryChildValueList(): # XXX do we really want to display all trade states ? for trade_state in portal.portal_categories.trade_state.getCategoryChildValueList(): # XXX do we really want to display all trade states ?
state_id = trade_state.getReference() or trade_state.getId() state_id = trade_state.getRelativeUrl()
graph['node'][state_id] = dict( graph['node'][state_id] = dict(
_class='erp5.business_process.trade_state', _class='erp5.business_process.trade_state',
name=trade_state.getTranslatedTitle()) name=trade_state.getTranslatedTitle())
...@@ -32,12 +32,17 @@ def getBusinessProcessGraph(business_process): ...@@ -32,12 +32,17 @@ def getBusinessProcessGraph(business_process):
visited_business_process_set.add(business_process) visited_business_process_set.add(business_process)
for link in business_process.contentValues(portal_type='Business Link'): for link in business_process.contentValues(portal_type='Business Link'):
predecessor = 'start' predecessor = link.getPredecessor() or 'start'
if link.getPredecessor(): if predecessor not in graph['node']:
predecessor = link.getPredecessorReference() or link.getPredecessorId() graph['node'][predecessor] = dict(
successor = 'end' _class='erp5.business_process.trade_state',
if link.getSuccessor(): name="missing trade state %s" % predecessor)
successor = link.getSuccessorReference() or link.getSuccessorId()
successor = link.getSuccessor() or 'end'
if successor not in graph['node']:
graph['node'][predecessor] = dict(
_class='erp5.business_process.trade_state',
name="missing trade state %s" % successor)
graph['edge'][link.getRelativeUrl()] = dict( graph['edge'][link.getRelativeUrl()] = dict(
_class='erp5.business_process.business_link', _class='erp5.business_process.business_link',
...@@ -64,7 +69,7 @@ class_definition = { ...@@ -64,7 +69,7 @@ class_definition = {
'properties': { 'properties': {
'name': {'type': 'string', 'name': str(translateString('Name'))}, 'name': {'type': 'string', 'name': str(translateString('Name'))},
'trade_phase': {'type': 'string', 'name': str(translateString('Trade Phase')), 'enum': [''] + [ 'trade_phase': {'type': 'string', 'name': str(translateString('Trade Phase')), 'enum': [''] + [
trade_phase.getId() for trade_phase in portal.portal_categories.trade_phase.getCategoryChildValueList(local_sort_on=('int_index', 'title'))]}, trade_phase.getRelativeUrl() for trade_phase in portal.portal_categories.trade_phase.getCategoryChildValueList(local_sort_on=('int_index', 'title'))]},
} }
} }
} }
......
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