~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/addons/base/ir/workflow/workflow_print.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import psycopg
 
2
import pydot
 
3
 
 
4
wkf_id = 193
 
5
 
 
6
db = psycopg.connect('dbname=terp', serialize=0)
 
7
cr=db.cursor()
 
8
 
 
9
def graph_get(cr, graph, wkf_id, nested=True):
 
10
        cr.execute('select * from wkf_activity where wkf_id=%d', (wkf_id,))
 
11
        nodes = cr.dictfetchall()
 
12
        activities = {}
 
13
        actfrom = {}
 
14
        actto = {}
 
15
        for n in nodes:
 
16
                activities[n['id']] = n
 
17
                if n['subflow_id'] and nested:
 
18
                        cr.execute('select * from wkf where id=%d', (n['subflow_id'],))
 
19
                        wkfinfo = cr.dictfetchone()
 
20
                        graph2 = pydot.Cluster('subflow'+str(n['subflow_id']), fontsize=10, label = "Subflow: "+n['name']+'\\nOSV: '+wkfinfo['osv'])
 
21
                        (s1,s2) = graph_get(cr, graph2, n['subflow_id'], nested)
 
22
                        graph.add_subgraph(graph2)
 
23
                        actfrom[n['id']] = s2
 
24
                        actto[n['id']] = s1
 
25
                else:
 
26
                        args = {}
 
27
                        if n['flow_start'] or n['flow_stop']:
 
28
                                args['style']='filled'
 
29
                                args['color']='lightgrey'
 
30
                        args['label']=n['name']
 
31
                        if n['action']:
 
32
                                args['label']+='\\n'+n['action']
 
33
                        if n['subflow_id']:
 
34
                                args['shape'] = 'box'
 
35
                        graph.add_node(pydot.Node(n['id'], **args))
 
36
                        actfrom[n['id']] = n['id']
 
37
                        actto[n['id']] = n['id']
 
38
        cr.execute('select * from wkf_transition where act_from in ('+','.join(map(lambda x: str(x['id']),nodes))+')')
 
39
        transitions = cr.dictfetchall()
 
40
        for t in transitions:
 
41
                args = {}
 
42
                args['label'] = str(t['condition'])
 
43
                if t['signal']:
 
44
                        args['label'] += '\\n'+str(t['signal'])
 
45
                        args['style'] = 'bold'
 
46
 
 
47
                if activities[t['act_from']]['split_mode']=='AND':
 
48
                        args['arrowtail']='box'
 
49
                elif str(activities[t['act_from']]['split_mode'])=='OR ':
 
50
                        args['arrowtail']='inv'
 
51
 
 
52
                if activities[t['act_to']]['join_mode']=='AND':
 
53
                        args['arrowhead']='crow'
 
54
 
 
55
                graph.add_edge(pydot.Edge(actfrom[t['act_from']],actto[t['act_to']], fontsize=8, **args))
 
56
        nodes = cr.dictfetchall()
 
57
        cr.execute('select id from wkf_activity where flow_start=True limit 1')
 
58
        start = cr.fetchone()[0]
 
59
        cr.execute('select id from wkf_activity where flow_stop=True limit 1')
 
60
        stop = cr.fetchone()[0]
 
61
        return (start,stop)
 
62
 
 
63
cr.execute('select * from wkf where id=%d', (wkf_id,))
 
64
wkfinfo = cr.dictfetchone()
 
65
graph = pydot.Dot(fontsize = 16, label = "\\n\\nWorkflow: %s\\n OSV: %s"% (wkfinfo['name'],wkfinfo['osv']))
 
66
graph_get(cr, graph, wkf_id, True)
 
67
graph.write_ps('/tmp/a.ps', prog='dot')
 
68