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
|
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):
|
class process_process(osv.osv):
|
||||||
_name = "process.process"
|
_name = "process.process"
|
||||||
_description = "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):
|
def graph_get(self, cr, uid, id, res_model, res_id, scale, context):
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
|
|
||||||
process = pool.get('process.process').browse(cr, uid, [id])[0]
|
process = pool.get('process.process').browse(cr, uid, [id])[0]
|
||||||
current_object = pool.get(res_model).browse(cr, uid, [res_id])[0]
|
current_object = pool.get(res_model).browse(cr, uid, [res_id])[0]
|
||||||
|
|
||||||
nodes = {}
|
nodes = {}
|
||||||
start = []
|
start = []
|
||||||
transitions = {}
|
transitions = {}
|
||||||
|
|
||||||
for node in process.node_ids:
|
for node in process.node_ids:
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
data['name'] = node.name
|
data['name'] = node.name
|
||||||
data['menu'] = (node.menu_id or None) and node.menu_id.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['model'] = (node.model_id or None) and node.model_id.model
|
||||||
data['kind'] = node.kind
|
data['kind'] = node.kind
|
||||||
data['notes'] = node.note
|
data['notes'] = node.note
|
||||||
data['active'] = 0
|
data['active'] = 0
|
||||||
|
data['gray'] = 0
|
||||||
|
|
||||||
if node.kind == "state" and node.model_id and node.model_id.model == res_model:
|
if node.kind == "state" and node.model_id and node.model_id.model == res_model:
|
||||||
states = node.model_states
|
try:
|
||||||
states = (states or []) and states.split(',')
|
data['active'] = eval(node.model_states, Env(current_object));
|
||||||
data['active'] = not states or current_object.state in states
|
except Exception, e:
|
||||||
|
# waring: invalid state expression
|
||||||
elif node.kind == "router":
|
pass
|
||||||
#TODO:
|
|
||||||
pass
|
if not data['active']:
|
||||||
|
try:
|
||||||
elif node.kind == "subflow":
|
gray = False
|
||||||
#TODO: subflow
|
for cond in node.condition_ids:
|
||||||
pass
|
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
|
nodes[node.id] = data
|
||||||
if node.flow_start:
|
if node.flow_start:
|
||||||
|
@ -129,7 +146,7 @@ class process_node(osv.osv):
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Name', size=30,required=True),
|
'name': fields.char('Name', size=30,required=True),
|
||||||
'process_id': fields.many2one('process.process', 'Process', 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'),
|
'menu_id': fields.many2one('ir.ui.menu', 'Related Menu'),
|
||||||
'note': fields.text('Notes'),
|
'note': fields.text('Notes'),
|
||||||
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
|
'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'),
|
'flow_start': fields.boolean('Starting Flow'),
|
||||||
'transition_in': fields.one2many('process.transition', 'target_node_id', 'Starting Transitions'),
|
'transition_in': fields.one2many('process.transition', 'target_node_id', 'Starting Transitions'),
|
||||||
'transition_out': fields.one2many('process.transition', 'source_node_id', 'Ending Transitions'),
|
'transition_out': fields.one2many('process.transition', 'source_node_id', 'Ending Transitions'),
|
||||||
|
'condition_ids': fields.one2many('process.condition', 'node_id', 'Conditions')
|
||||||
}
|
}
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'kind': lambda *args: 'state',
|
'kind': lambda *args: 'state',
|
||||||
|
@ -145,6 +163,17 @@ class process_node(osv.osv):
|
||||||
}
|
}
|
||||||
process_node()
|
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):
|
class process_transition(osv.osv):
|
||||||
_name = 'process.transition'
|
_name = 'process.transition'
|
||||||
_description ='Process Transitions'
|
_description ='Process Transitions'
|
||||||
|
|
|
@ -71,6 +71,21 @@
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</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">
|
<page string="Extra Information">
|
||||||
<field name="note" nolabel="1" colspan="4"/>
|
<field name="note" nolabel="1" colspan="4"/>
|
||||||
</page>
|
</page>
|
||||||
|
|
Loading…
Reference in New Issue