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

« back to all changes in this revision

Viewing changes to bin/addons/base/ir/workflow/instance_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 = 231
 
5
 
 
6
db = psycopg.connect('dbname=terp', serialize=0)
 
7
cr=db.cursor()
 
8
 
 
9
def graph_get(cr, graph, wkf_id, nested=True, workitem={}):
 
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,workitem)
 
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
                        if n['id'] in workitem:
 
36
                                args['label']+='\\nx '+str(workitem[n['id']])
 
37
                                args['color'] = "red"
 
38
                        graph.add_node(pydot.Node(n['id'], **args))
 
39
                        actfrom[n['id']] = n['id']
 
40
                        actto[n['id']] = n['id']
 
41
        cr.execute('select * from wkf_transition where act_from in ('+','.join(map(lambda x: str(x['id']),nodes))+')')
 
42
        transitions = cr.dictfetchall()
 
43
        for t in transitions:
 
44
                args = {}
 
45
                args['label'] = str(t['condition'])
 
46
                if t['signal']:
 
47
                        args['label'] += '\\n'+str(t['signal'])
 
48
                        args['style'] = 'bold'
 
49
 
 
50
                if activities[t['act_from']]['split_mode']=='AND':
 
51
                        args['arrowtail']='box'
 
52
                elif str(activities[t['act_from']]['split_mode'])=='OR ':
 
53
                        args['arrowtail']='inv'
 
54
 
 
55
                if activities[t['act_to']]['join_mode']=='AND':
 
56
                        args['arrowhead']='crow'
 
57
 
 
58
                graph.add_edge(pydot.Edge(actfrom[t['act_from']],actto[t['act_to']], fontsize=8, **args))
 
59
        nodes = cr.dictfetchall()
 
60
        cr.execute('select id from wkf_activity where flow_start=True limit 1')
 
61
        start = cr.fetchone()[0]
 
62
        cr.execute('select id from wkf_activity where flow_stop=True limit 1')
 
63
        stop = cr.fetchone()[0]
 
64
        return (start,stop)
 
65
 
 
66
def graph_instance_get(cr, graph, inst_id, nested=False):
 
67
        workitems = {}
 
68
        cr.execute('select * from wkf_instance where id=%d', (inst_id,))
 
69
        inst = cr.dictfetchone()
 
70
 
 
71
        def workitem_get(instance):
 
72
                cr.execute('select act_id,count(*) from wkf_workitem where inst_id=%d group by act_id', (instance,))
 
73
                workitems = dict(cr.fetchall())
 
74
 
 
75
                cr.execute('select subflow_id from wkf_workitem where inst_id=%d', (instance,))
 
76
                for (subflow_id,) in cr.fetchall():
 
77
                        workitems.update(workitem_get(subflow_id))
 
78
                return workitems
 
79
 
 
80
        graph_get(cr, graph, inst['wkf_id'], nested, workitem_get(inst_id))
 
81
 
 
82
 
 
83
cr.execute('select * from wkf where id=%d', (wkf_id,))
 
84
wkfinfo = cr.dictfetchone()
 
85
graph = pydot.Dot(fontsize = 16, label = "\\n\\nWorkflow: %s\\n OSV: %s"% (wkfinfo['name'],wkfinfo['osv']))
 
86
graph_instance_get(cr, graph, 1155, True)
 
87
graph.write_ps('/tmp/a.ps', prog='dot')
 
88