1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2005-TODAY TINY SPRL. (http://tiny.be) All Rights Reserved.
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ##############################################################################
32 from osv import fields, osv
34 class process_process(osv.osv):
35 _name = "process.process"
36 _description = "Process"
38 'name': fields.char('Name', size=30,required=True),
39 'active': fields.boolean('Active'),
40 'note': fields.text('Notes'),
41 'node_ids': fields.one2many('process.node', 'process_id', 'Nodes')
44 'active' : lambda *a: True,
47 def graph_get(self, cr, uid, id, res_model, res_id, scale, context):
48 pool = pooler.get_pool(cr.dbname)
49 process = pool.get('process.process').browse(cr, uid, [id])[0]
50 current_object = pool.get(res_model).browse(cr, uid, [res_id])[0]
54 for node in process.node_ids:
58 data['name'] = node.name
59 data['menu'] = (node.menu_id or None) and node.menu_id.name
60 data['model'] = (node.model_id or None) and node.model_id.model
61 data['kind'] = node.kind
64 if node.kind == "state" and node.model_id and node.model_id.model == res_model:
65 states = node.model_states
66 states = (states or []) and states.split(',')
67 data['active'] = (states and current_object.state in states) or not states
69 elif node.kind == "router":
73 elif node.kind == "subflow":
81 for tr in node.transition_out:
83 data['name'] = tr.name
84 data['source'] = tr.source_node_id.id
85 data['target'] = tr.target_node_id.id
86 data['buttons'] = buttons = []
87 for b in tr.action_ids:
89 button['name'] = b.name
90 buttons.append(button)
91 data['roles'] = roles = []
92 for r in tr.transition_ids:
95 role['name'] = r.role_id.name
97 transitions[tr.id] = data
99 g = tools.graph(nodes.keys(), map(lambda x: (x['source'], x['target']), transitions.values()))
101 #g.scale(100, 100, 180, 120)
103 graph = g.result_get()
106 for k,v in nodes.items():
115 for k, v in nodes.items():
117 v['y'] = min(y - miny + 10, y)
118 return dict(nodes=nodes, transitions=transitions)
122 class process_node(osv.osv):
123 _name = 'process.node'
124 _description ='Process Nodes'
126 'name': fields.char('Name', size=30,required=True),
127 'process_id': fields.many2one('process.process', 'Process', required=True),
128 'kind': fields.selection([('state','State'),('router','Router'),('subflow','Subflow')],'Kind of Node', required=True),
129 'menu_id': fields.many2one('ir.ui.menu', 'Related Menu'),
130 'note': fields.text('Notes'),
131 'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
132 'model_states': fields.char('States Expression', size=128),
133 'flow_start': fields.boolean('Starting Flow'),
134 'transition_in': fields.one2many('process.transition', 'target_node_id', 'Starting Transitions'),
135 'transition_out': fields.one2many('process.transition', 'source_node_id', 'Ending Transitions'),
138 'kind': lambda *args: 'state',
139 'model_states': lambda *args: False,
140 'flow_start': lambda *args: False,
144 class process_transition(osv.osv):
145 _name = 'process.transition'
146 _description ='Process Transitions'
148 'name': fields.char('Name', size=32, required=True),
149 'source_node_id': fields.many2one('process.node', 'Source Node', required=True, ondelete='cascade'),
150 'target_node_id': fields.many2one('process.node', 'Target Node', required=True, ondelete='cascade'),
151 'action_ids': fields.one2many('process.transition.action', 'transition_id', 'Buttons'),
152 'transition_ids': fields.many2many('workflow.transition', 'process_transition_ids', 'ptr_id', 'wtr_id', 'Workflow Transitions'),
153 'note': fields.text('Description'),
157 class process_transition_action(osv.osv):
158 _name = 'process.transition.action'
159 _description ='Process Transitions Actions'
161 'name': fields.char('Name', size=32, required=True),
162 'state': fields.selection([('dummy','Dummy'),
163 ('method','Object Method'),
164 ('workflow','Workflow Trigger'),
165 ('action','Action')], 'Type', required=True),
166 'action': fields.char('Action ID', size=64, states={
167 'dummy':[('readonly',1)],
168 'method':[('required',1)],
169 'workflow':[('required',1)],
170 'action':[('required',1)],
172 'transition_id': fields.many2one('process.transition', 'Transition', required=True, ondelete='cascade')
175 'state': lambda *args: 'dummy',
177 process_transition_action()