Process node conditions.
bzr revid: ame@tinyerp.com-20080918083245-wya7jfes1s92cs9k
This commit is contained in:
parent
8aaac71130
commit
fe17e91254
|
@ -31,6 +31,17 @@ import pooler, tools
|
|||
|
||||
from osv import fields, osv
|
||||
|
||||
class Env(dict):
|
||||
|
||||
def __init__(self, parent):
|
||||
self.__parent = parent
|
||||
|
||||
def __getitem__(self, name):
|
||||
if name == '__parent':
|
||||
return super(Env, self).__getitem__(name)
|
||||
|
||||
return self.__parent[name]
|
||||
|
||||
class process_process(osv.osv):
|
||||
_name = "process.process"
|
||||
_description = "Process"
|
||||
|
@ -46,34 +57,40 @@ class process_process(osv.osv):
|
|||
|
||||
def graph_get(self, cr, uid, id, res_model, res_id, scale, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
process = pool.get('process.process').browse(cr, uid, [id])[0]
|
||||
current_object = pool.get(res_model).browse(cr, uid, [res_id])[0]
|
||||
|
||||
nodes = {}
|
||||
start = []
|
||||
transitions = {}
|
||||
|
||||
for node in process.node_ids:
|
||||
|
||||
data = {}
|
||||
|
||||
data['name'] = node.name
|
||||
data['menu'] = (node.menu_id or None) and node.menu_id.name
|
||||
data['model'] = (node.model_id or None) and node.model_id.model
|
||||
data['kind'] = node.kind
|
||||
data['notes'] = node.note
|
||||
data['active'] = 0
|
||||
|
||||
data['gray'] = 0
|
||||
|
||||
if node.kind == "state" and node.model_id and node.model_id.model == res_model:
|
||||
states = node.model_states
|
||||
states = (states or []) and states.split(',')
|
||||
data['active'] = not states or current_object.state in states
|
||||
|
||||
elif node.kind == "router":
|
||||
#TODO:
|
||||
pass
|
||||
|
||||
elif node.kind == "subflow":
|
||||
#TODO: subflow
|
||||
pass
|
||||
try:
|
||||
data['active'] = eval(node.model_states, Env(current_object));
|
||||
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:
|
||||
gray = gray or eval(cond.model_states, Env(current_object))
|
||||
data['gray'] = gray
|
||||
except:
|
||||
pass
|
||||
|
||||
nodes[node.id] = data
|
||||
if node.flow_start:
|
||||
|
@ -129,7 +146,7 @@ class process_node(osv.osv):
|
|||
_columns = {
|
||||
'name': fields.char('Name', size=30,required=True),
|
||||
'process_id': fields.many2one('process.process', 'Process', required=True),
|
||||
'kind': fields.selection([('state','State'),('router','Router'),('subflow','Subflow')],'Kind of Node', required=True),
|
||||
'kind': fields.selection([('state','State'), ('subflow','Subflow')], 'Kind of Node', required=True),
|
||||
'menu_id': fields.many2one('ir.ui.menu', 'Related Menu'),
|
||||
'note': fields.text('Notes'),
|
||||
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
|
||||
|
@ -137,6 +154,7 @@ class process_node(osv.osv):
|
|||
'flow_start': fields.boolean('Starting Flow'),
|
||||
'transition_in': fields.one2many('process.transition', 'target_node_id', 'Starting Transitions'),
|
||||
'transition_out': fields.one2many('process.transition', 'source_node_id', 'Ending Transitions'),
|
||||
'condition_ids': fields.one2many('process.condition', 'node_id', 'Conditions')
|
||||
}
|
||||
_defaults = {
|
||||
'kind': lambda *args: 'state',
|
||||
|
@ -145,6 +163,17 @@ class process_node(osv.osv):
|
|||
}
|
||||
process_node()
|
||||
|
||||
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()
|
||||
|
||||
class process_transition(osv.osv):
|
||||
_name = 'process.transition'
|
||||
_description ='Process Transitions'
|
||||
|
|
|
@ -71,6 +71,21 @@
|
|||
</form>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Conditions">
|
||||
<field name="condition_ids" nolabel="1" colspan="4">
|
||||
<tree string="Conditions">
|
||||
<field name="name"/>
|
||||
<field name="model_id"/>
|
||||
<field name="model_states"/>
|
||||
</tree>
|
||||
<form string="Condition">
|
||||
<field name="name"/>
|
||||
<field name="model_id"/>
|
||||
<newline/>
|
||||
<field name="model_states" colspan="4"/>
|
||||
</form>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Extra Information">
|
||||
<field name="note" nolabel="1" colspan="4"/>
|
||||
</page>
|
||||
|
|
Loading…
Reference in New Issue