Adding Graph Rendering Routine in the Trunk
authorFabien Pinckaers <fp@tinyerp.com>
Mon, 21 Apr 2008 07:09:08 +0000 (07:09 +0000)
committerFabien Pinckaers <fp@tinyerp.com>
Mon, 21 Apr 2008 07:09:08 +0000 (07:09 +0000)
bzr revid: fp@tinyerp.com-55457de5949ef31ba3aa2b82612f3911afed2ecf

bin/addons/base/ir/workflow/workflow.py
bin/tools/__init__.py
bin/tools/graph.py

index f40093d..886688f 100644 (file)
@@ -28,6 +28,7 @@
 ##############################################################################
 
 from osv import fields, osv
+from tools import graph
 import netsvc
 
 class workflow(osv.osv):
@@ -51,6 +52,32 @@ class workflow(osv.osv):
                wf_service.clear_cache(cr, user)
                return super(workflow, self).write(cr, user, ids, vals, context=context)
 
+       #
+       # scale = [stepx, stepy, posx, posy ]
+       # 
+       def graph_get(self, cr, uid, id, scale, context={}):
+               nodes= []
+               transitions = []
+               start = []
+               tres = []
+               workflow = self.browse(cr, uid, id, context)
+               for a in workflow.activities:
+                       nodes.append((a.id,a.name))
+                       if a.flow_start:
+                               start.append((a.id,a.name))
+                       for t in a.out_transitions:
+                               transitions.append( ((a.id,a.name), (t.act_to.id,t.act_to.name)) )
+                               tres.append((a.id,t.act_to.id))
+               g  = graph(nodes, transitions)
+               g.process(start)
+               g.scale(*scale)
+               result = g.result_get()
+               results = {}
+               for r in result.items():
+                       r[1]['name'] = r[0][1]
+                       results[str(r[0][0])] = r[1]
+               return {'node': results, 'transition': tres}
+
        def create(self, cr, user, vals, context=None):
                if not context:
                        context={}
index 455a321..6088f5e 100644 (file)
@@ -2,3 +2,4 @@ from config import *
 from misc import *
 from convert import *
 from translate import *
+from graph import graph
index 25cbd9b..6dde9ee 100644 (file)
@@ -58,7 +58,7 @@ class graph(object):
        def process(self, starting_node):
                pos = (len(starting_node) - 1.0)/2.0
                for s in starting_node:
-                       g.process_ranking(s)
+                       self.process_ranking(s)
                        self.result[s]['x'] = pos
                        pos += 1.0