Add workflow graph on ir.model

issue5292
review15961002
This commit is contained in:
Cédric Krier
2016-03-15 18:59:11 +01:00
parent ad60794d73
commit 33d8f038d7
4 changed files with 71 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add workflow graph on ir.model
* Add context model on ir.action.act_window
* Switch to WSGI API
* Limit the login size in LoginAttempt
+1
View File
@@ -98,4 +98,5 @@ def register():
module='ir', type_='wizard')
Pool.register(
ModelGraph,
ModelWorkflowGraph,
module='ir', type_='report')
+57 -1
View File
@@ -12,7 +12,7 @@ try:
except ImportError:
import json
from ..model import ModelView, ModelSQL, fields, Unique
from ..model import ModelView, ModelSQL, Workflow, fields, Unique
from ..report import Report
from ..wizard import Wizard, StateView, StateAction, Button
from ..transaction import Transaction
@@ -31,6 +31,7 @@ except ImportError:
__all__ = [
'Model', 'ModelField', 'ModelAccess', 'ModelFieldAccess', 'ModelButton',
'ModelData', 'PrintModelGraphStart', 'PrintModelGraph', 'ModelGraph',
'ModelWorkflowGraph',
]
IDENTIFIER = re.compile(r'^[a-zA-z_][a-zA-Z0-9_]*$')
@@ -1095,3 +1096,58 @@ class ModelGraph(Report):
edge = pydot.Edge(str(tail), str(head), **args)
graph.add_edge(edge)
class ModelWorkflowGraph(Report):
__name__ = 'ir.model.workflow_graph'
@classmethod
def execute(cls, ids, data):
import pydot
pool = Pool()
Model = pool.get('ir.model')
ActionReport = pool.get('ir.action.report')
action_report_ids = ActionReport.search([
('report_name', '=', cls.__name__)
])
if not action_report_ids:
raise Exception('Error', 'Report (%s) not find!' % cls.__name__)
action_report = ActionReport(action_report_ids[0])
models = Model.browse(ids)
graph = pydot.Dot()
graph.set('center', '1')
graph.set('ratio', 'auto')
direction = Transaction().context.get('language_direction', 'ltr')
graph.set('rankdir', {'ltr': 'LR', 'rtl': 'RL'}[direction])
cls.fill_graph(models, graph)
data = graph.create(prog='dot', format='png')
return ('png', fields.Binary.cast(data), False, action_report.name)
@classmethod
def fill_graph(cls, models, graph):
'Fills pydot graph with models wizard.'
import pydot
pool = Pool()
for record in models:
Model = pool.get(record.model)
if not issubclass(Model, Workflow):
continue
subgraph = pydot.Cluster('%s' % record.id, label=record.model)
graph.add_subgraph(subgraph)
state_field = getattr(Model, Model._transition_state)
for state, _ in state_field.selection:
node = pydot.Node(
'"%s"' % state, shape='octagon', label=state)
subgraph.add_node(node)
for from_, to in Model._transitions:
edge = pydot.Edge('"%s"' % from_, '"%s"' % to,
arrowhead='normal')
subgraph.add_edge(edge)
+12
View File
@@ -143,6 +143,18 @@ this repository contains the full copyright notices and license terms. -->
<field name="action" ref="print_model_graph"/>
</record>
<record model="ir.action.report" id="report_model_workflow_graph">
<field name="name">Workflow Graph</field>
<field name="model">ir.model</field>
<field name="report_name">ir.model.workflow_graph</field>
</record>
<record model="ir.action.keyword"
id="print_model_workflow_graph_keyword">
<field name="keyword">form_print</field>
<field name="model">ir.model,-1</field>
<field name="action" ref="report_model_workflow_graph"/>
</record>
<record model="ir.ui.view" id="model_button_view_list">
<field name="model">ir.model.button</field>
<field name="type">tree</field>