2008-07-23 14:41:47 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
2008-07-14 17:01:30 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005-TODAY TINY SPRL. (http://tiny.be) All Rights Reserved.
|
|
|
|
#
|
|
|
|
# WARNING: This program as such is intended to be used by professional
|
|
|
|
# programmers who take the whole responsability of assessing all potential
|
|
|
|
# consequences resulting from its eventual inadequacies and bugs
|
|
|
|
# End users who are looking for a ready-to-use solution with commercial
|
|
|
|
# garantees and support are strongly adviced to contract a Free Software
|
|
|
|
# Service Company
|
|
|
|
#
|
|
|
|
# This program is Free Software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import netsvc
|
2008-09-11 11:45:45 +00:00
|
|
|
import pooler, tools
|
2008-07-14 17:01:30 +00:00
|
|
|
|
2008-09-11 11:45:45 +00:00
|
|
|
from osv import fields, osv
|
2008-07-14 17:01:30 +00:00
|
|
|
|
2008-09-18 08:32:45 +00:00
|
|
|
class Env(dict):
|
2008-09-18 09:26:33 +00:00
|
|
|
|
|
|
|
def __init__(self, obj, user):
|
|
|
|
self.__obj = obj
|
|
|
|
self.__usr = user
|
|
|
|
|
2008-09-18 08:32:45 +00:00
|
|
|
def __getitem__(self, name):
|
2008-09-18 09:26:33 +00:00
|
|
|
|
|
|
|
if name in ('__obj', '__user'):
|
|
|
|
return super(ExprContext, self).__getitem__(name)
|
|
|
|
|
|
|
|
if name == 'user':
|
|
|
|
return self.__user
|
|
|
|
|
|
|
|
if name == 'object':
|
|
|
|
return self.__obj
|
|
|
|
|
|
|
|
return self.__obj[name]
|
2008-09-18 08:32:45 +00:00
|
|
|
|
2008-09-08 08:56:23 +00:00
|
|
|
class process_process(osv.osv):
|
|
|
|
_name = "process.process"
|
|
|
|
_description = "Process"
|
2008-07-14 17:01:30 +00:00
|
|
|
_columns = {
|
2008-09-04 07:15:18 +00:00
|
|
|
'name': fields.char('Name', size=30,required=True),
|
2008-07-14 17:01:30 +00:00
|
|
|
'active': fields.boolean('Active'),
|
|
|
|
'note': fields.text('Notes'),
|
2008-09-08 08:56:23 +00:00
|
|
|
'node_ids': fields.one2many('process.node', 'process_id', 'Nodes')
|
2008-07-14 17:01:30 +00:00
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'active' : lambda *a: True,
|
|
|
|
}
|
2008-09-11 11:45:45 +00:00
|
|
|
|
|
|
|
def graph_get(self, cr, uid, id, res_model, res_id, scale, context):
|
|
|
|
pool = pooler.get_pool(cr.dbname)
|
2008-09-18 08:32:45 +00:00
|
|
|
|
2008-09-11 11:45:45 +00:00
|
|
|
process = pool.get('process.process').browse(cr, uid, [id])[0]
|
2008-09-16 06:15:30 +00:00
|
|
|
current_object = pool.get(res_model).browse(cr, uid, [res_id])[0]
|
2008-09-18 09:26:33 +00:00
|
|
|
current_user = pool.get('res.users').browse(cr, uid, [uid])[0]
|
|
|
|
|
|
|
|
expr_context = Env(current_object, current_user)
|
2008-09-18 08:32:45 +00:00
|
|
|
|
2008-09-11 11:45:45 +00:00
|
|
|
nodes = {}
|
|
|
|
start = []
|
|
|
|
transitions = {}
|
|
|
|
|
2008-09-18 08:32:45 +00:00
|
|
|
for node in process.node_ids:
|
2008-09-11 11:45:45 +00:00
|
|
|
data = {}
|
|
|
|
data['name'] = node.name
|
2008-09-16 08:45:33 +00:00
|
|
|
data['menu'] = (node.menu_id or None) and node.menu_id.name
|
|
|
|
data['model'] = (node.model_id or None) and node.model_id.model
|
2008-09-16 06:15:30 +00:00
|
|
|
data['kind'] = node.kind
|
2008-09-17 13:37:18 +00:00
|
|
|
data['notes'] = node.note
|
2008-09-16 06:15:30 +00:00
|
|
|
data['active'] = 0
|
2008-09-18 08:32:45 +00:00
|
|
|
data['gray'] = 0
|
|
|
|
|
2008-09-16 08:45:33 +00:00
|
|
|
if node.kind == "state" and node.model_id and node.model_id.model == res_model:
|
2008-09-18 08:32:45 +00:00
|
|
|
try:
|
2008-09-18 09:26:33 +00:00
|
|
|
data['active'] = eval(node.model_states, expr_context);
|
2008-09-18 08:32:45 +00:00
|
|
|
except Exception, e:
|
|
|
|
# waring: invalid state expression
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not data['active']:
|
|
|
|
try:
|
|
|
|
gray = False
|
|
|
|
for cond in node.condition_ids:
|
|
|
|
if cond.model_id and cond.model_id.model == res_model:
|
2008-09-18 09:26:33 +00:00
|
|
|
gray = gray or eval(cond.model_states, expr_context)
|
2008-09-18 08:32:45 +00:00
|
|
|
data['gray'] = gray
|
|
|
|
except:
|
|
|
|
pass
|
2008-09-11 11:45:45 +00:00
|
|
|
|
|
|
|
nodes[node.id] = data
|
|
|
|
if node.flow_start:
|
|
|
|
start.append(node.id)
|
|
|
|
|
2008-09-16 14:19:07 +00:00
|
|
|
for tr in node.transition_out:
|
2008-09-11 11:45:45 +00:00
|
|
|
data = {}
|
|
|
|
data['name'] = tr.name
|
2008-09-16 08:45:33 +00:00
|
|
|
data['source'] = tr.source_node_id.id
|
|
|
|
data['target'] = tr.target_node_id.id
|
2008-09-17 13:37:18 +00:00
|
|
|
data['notes'] = tr.note
|
2008-09-12 14:03:31 +00:00
|
|
|
data['buttons'] = buttons = []
|
|
|
|
for b in tr.action_ids:
|
|
|
|
button = {}
|
|
|
|
button['name'] = b.name
|
2008-09-17 13:37:18 +00:00
|
|
|
button['state'] = b.state
|
|
|
|
button['action'] = b.action
|
2008-09-12 14:03:31 +00:00
|
|
|
buttons.append(button)
|
|
|
|
data['roles'] = roles = []
|
2008-09-16 14:19:07 +00:00
|
|
|
for r in tr.transition_ids:
|
2008-09-17 05:28:32 +00:00
|
|
|
if r.role_id:
|
|
|
|
role = {}
|
|
|
|
role['name'] = r.role_id.name
|
|
|
|
roles.append(role)
|
2008-09-11 11:45:45 +00:00
|
|
|
transitions[tr.id] = data
|
|
|
|
|
|
|
|
g = tools.graph(nodes.keys(), map(lambda x: (x['source'], x['target']), transitions.values()))
|
|
|
|
g.process(start)
|
|
|
|
#g.scale(100, 100, 180, 120)
|
|
|
|
g.scale(*scale)
|
|
|
|
graph = g.result_get()
|
|
|
|
miny = -1
|
|
|
|
|
|
|
|
for k,v in nodes.items():
|
|
|
|
x = graph[k]['y']
|
|
|
|
y = graph[k]['x']
|
|
|
|
if miny == -1:
|
|
|
|
miny = y
|
|
|
|
miny = min(y, miny)
|
|
|
|
v['x'] = x
|
|
|
|
v['y'] = y
|
|
|
|
|
|
|
|
for k, v in nodes.items():
|
|
|
|
y = v['y']
|
|
|
|
v['y'] = min(y - miny + 10, y)
|
|
|
|
return dict(nodes=nodes, transitions=transitions)
|
|
|
|
|
2008-09-08 08:56:23 +00:00
|
|
|
process_process()
|
2008-07-14 17:01:30 +00:00
|
|
|
|
2008-09-08 08:56:23 +00:00
|
|
|
class process_node(osv.osv):
|
|
|
|
_name = 'process.node'
|
|
|
|
_description ='Process Nodes'
|
2008-07-14 17:01:30 +00:00
|
|
|
_columns = {
|
2008-09-04 07:15:18 +00:00
|
|
|
'name': fields.char('Name', size=30,required=True),
|
2008-09-08 08:56:23 +00:00
|
|
|
'process_id': fields.many2one('process.process', 'Process', required=True),
|
2008-09-18 08:32:45 +00:00
|
|
|
'kind': fields.selection([('state','State'), ('subflow','Subflow')], 'Kind of Node', required=True),
|
2008-07-14 17:01:30 +00:00
|
|
|
'menu_id': fields.many2one('ir.ui.menu', 'Related Menu'),
|
|
|
|
'note': fields.text('Notes'),
|
2008-08-21 13:50:55 +00:00
|
|
|
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
|
2008-07-14 17:01:30 +00:00
|
|
|
'model_states': fields.char('States Expression', size=128),
|
|
|
|
'flow_start': fields.boolean('Starting Flow'),
|
2008-09-16 14:19:07 +00:00
|
|
|
'transition_in': fields.one2many('process.transition', 'target_node_id', 'Starting Transitions'),
|
|
|
|
'transition_out': fields.one2many('process.transition', 'source_node_id', 'Ending Transitions'),
|
2008-09-18 08:32:45 +00:00
|
|
|
'condition_ids': fields.one2many('process.condition', 'node_id', 'Conditions')
|
2008-07-14 17:01:30 +00:00
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'kind': lambda *args: 'state',
|
|
|
|
'model_states': lambda *args: False,
|
|
|
|
'flow_start': lambda *args: False,
|
|
|
|
}
|
2008-09-08 08:56:23 +00:00
|
|
|
process_node()
|
2008-07-14 17:01:30 +00:00
|
|
|
|
2008-09-18 08:32:45 +00:00
|
|
|
class process_node_condition(osv.osv):
|
|
|
|
_name = 'process.condition'
|
|
|
|
_description = 'Condition'
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Name', size=30, required=True),
|
|
|
|
'node_id': fields.many2one('process.node', 'Node', required=True),
|
|
|
|
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
|
|
|
|
'model_states': fields.char('Expression', required=True, size=128)
|
|
|
|
}
|
|
|
|
process_node_condition()
|
|
|
|
|
2008-09-08 08:56:23 +00:00
|
|
|
class process_transition(osv.osv):
|
|
|
|
_name = 'process.transition'
|
|
|
|
_description ='Process Transitions'
|
2008-07-14 17:01:30 +00:00
|
|
|
_columns = {
|
2008-09-04 07:15:18 +00:00
|
|
|
'name': fields.char('Name', size=32, required=True),
|
2008-09-16 08:45:33 +00:00
|
|
|
'source_node_id': fields.many2one('process.node', 'Source Node', required=True, ondelete='cascade'),
|
|
|
|
'target_node_id': fields.many2one('process.node', 'Target Node', required=True, ondelete='cascade'),
|
|
|
|
'action_ids': fields.one2many('process.transition.action', 'transition_id', 'Buttons'),
|
2008-09-16 14:19:07 +00:00
|
|
|
'transition_ids': fields.many2many('workflow.transition', 'process_transition_ids', 'ptr_id', 'wtr_id', 'Workflow Transitions'),
|
2008-07-14 17:01:30 +00:00
|
|
|
'note': fields.text('Description'),
|
|
|
|
}
|
2008-09-08 08:56:23 +00:00
|
|
|
process_transition()
|
2008-07-14 17:01:30 +00:00
|
|
|
|
2008-09-08 08:56:23 +00:00
|
|
|
class process_transition_action(osv.osv):
|
|
|
|
_name = 'process.transition.action'
|
|
|
|
_description ='Process Transitions Actions'
|
2008-07-14 17:01:30 +00:00
|
|
|
_columns = {
|
2008-09-04 07:15:18 +00:00
|
|
|
'name': fields.char('Name', size=32, required=True),
|
2008-09-16 08:45:33 +00:00
|
|
|
'state': fields.selection([('dummy','Dummy'),
|
|
|
|
('method','Object Method'),
|
|
|
|
('workflow','Workflow Trigger'),
|
|
|
|
('action','Action')], 'Type', required=True),
|
2008-07-14 17:01:30 +00:00
|
|
|
'action': fields.char('Action ID', size=64, states={
|
|
|
|
'dummy':[('readonly',1)],
|
|
|
|
'method':[('required',1)],
|
|
|
|
'workflow':[('required',1)],
|
|
|
|
'action':[('required',1)],
|
|
|
|
},),
|
2008-09-08 08:56:23 +00:00
|
|
|
'transition_id': fields.many2one('process.transition', 'Transition', required=True, ondelete='cascade')
|
2008-07-14 17:01:30 +00:00
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'state': lambda *args: 'dummy',
|
|
|
|
}
|
2008-09-08 08:56:23 +00:00
|
|
|
process_transition_action()
|
2008-07-14 17:01:30 +00:00
|
|
|
|