'active' : lambda *a: True,
}
+ def search_by_model(self, cr, uid, res_model, context):
+ pool = pooler.get_pool(cr.dbname)
+
+ model_ids = pool.get('ir.model').search(cr, uid, [('model', '=', res_model)])
+ if not model_ids:
+ return []
+
+ nodes = pool.get('process.node').search(cr, uid, [('model_id', 'in', model_ids)])
+ if not nodes:
+ return []
+
+ nodes = pool.get('process.node').browse(cr, uid, nodes, context)
+
+ unique = []
+ result = []
+
+ for node in nodes:
+ if node.process_id.id not in unique:
+ result.append((node.process_id.id, node.process_id.name))
+ unique.append(node.process_id.id)
+
+ return result
+
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]
expr_context = Env(current_object, current_user)
+ notes = process.note
nodes = {}
start = []
transitions = {}
+ states = dict(pool.get(res_model).fields_get(cr, uid, context=context).get('state', {}).get('selection', {}))
+ title = "%s - Resource: %s, State: %s" % (process.name, current_object.name, states.get(getattr(current_object, 'state'), 'N/A'))
+
+ perm = pool.get(res_model).perm_read(cr, uid, [res_id], context)[0]
+
for node in process.node_ids:
data = {}
data['name'] = node.name
data['model'] = (node.model_id or None) and node.model_id.model
data['kind'] = node.kind
+ data['subflow'] = (node.subflow_id or False) and [node.subflow_id.id, node.subflow_id.name]
data['notes'] = node.note
- data['active'] = 0
- data['gray'] = 0
+ data['active'] = False
+ data['gray'] = False
+ data['url'] = node.help_url
+
+ # chech whether directory_id from inherited from document2 is available
+ if hasattr(node, 'directory_id') and node.directory_id:
+ data['directory'] = "ftp://localhost:8021" #TODO: implement document_directory.get_url
+
+ # get assosiated workflow
+ if data['model']:
+ wkf_ids = self.pool.get('workflow').search(cr, uid, [('osv', '=', data['model'])])
+ data['workflow'] = (wkf_ids or False) and wkf_ids[0]
if node.menu_id:
data['menu'] = {'name': node.menu_id.complete_name, 'id': node.menu_id.id}
- if node.kind == "state" and node.model_id and node.model_id.model == res_model:
+ if node.model_id and node.model_id.model == res_model:
try:
- if eval(node.model_states, expr_context):
- data['active'] = current_object.name_get(context)[0][1]
+ data['active'] = eval(node.model_states, expr_context)
except Exception, e:
# waring: invalid state expression
pass
-
+
if not data['active']:
try:
gray = True
role = {}
role['name'] = r.role_id.name
roles.append(role)
+ for r in tr.role_ids:
+ role = {}
+ role['name'] = r.name
+ roles.append(role)
transitions[tr.id] = data
+ # now populate resource information
+ def update_relatives(nid, ref_id, ref_model):
+ relatives = []
+
+ for tid, tr in transitions.items():
+ if tr['source'] == nid:
+ relatives.append(tr['target'])
+ if tr['target'] == nid:
+ relatives.append(tr['source'])
+
+ if not ref_id:
+ nodes[nid]['res'] = False
+ return
+
+ nodes[nid]['res'] = resource = {'id': ref_id, 'model': ref_model}
+
+ refobj = pool.get(ref_model).browse(cr, uid, [ref_id], context)[0]
+ fields = pool.get(ref_model).fields_get(cr, uid, context=context)
+
+ resource['name'] = refobj.name_get(context)[0][1]
+ resource['perm'] = pool.get(ref_model).perm_read(cr, uid, [ref_id], context)[0]
+
+ for r in relatives:
+ node = nodes[r]
+ if 'res' not in node:
+ for n, f in fields.items():
+ if node['model'] == ref_model:
+ update_relatives(r, ref_id, ref_model)
+
+ elif f.get('relation') == node['model']:
+ rel = refobj[n]
+ if rel and isinstance(rel, list) :
+ rel = rel[0]
+ if isinstance(rel, basestring):
+ print "XXX: ", rel
+ try: # XXXXXXXXXXXXXXXXXXX
+ _id = (rel or False) and rel.id
+ _model = node['model']
+ update_relatives(r, _id, _model)
+ except:
+ pass
+
+ for nid, node in nodes.items():
+ if not node['gray'] and (node['active'] or node['model'] == res_model):
+ update_relatives(nid, res_id, res_model)
+ break
+
+ # calculate graph layout
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)
+ g.process(start)
+ g.scale(*scale) #g.scale(100, 100, 180, 120)
graph = g.result_get()
- miny = -1
+ # fix the height problem
+ miny = -1
for k,v in nodes.items():
x = graph[k]['y']
y = graph[k]['x']
for k, v in nodes.items():
y = v['y']
v['y'] = min(y - miny + 10, y)
- return dict(nodes=nodes, transitions=transitions)
+
+ return dict(title=title, perm=perm, notes=notes, nodes=nodes, transitions=transitions)
+
+ def copy(self, cr, uid, id, default=None, context={}):
+ """ Deep copy the entire process.
+ """
+
+ if not default:
+ default = {}
+
+ pool = pooler.get_pool(cr.dbname)
+ process = pool.get('process.process').browse(cr, uid, [id], context)[0]
+
+ nodes = {}
+ transitions = {}
+
+ # first copy all nodes and and map the new nodes with original for later use in transitions
+ for node in process.node_ids:
+ for t in node.transition_in:
+ tr = transitions.setdefault(t.id, {})
+ tr['target'] = node.id
+ for t in node.transition_out:
+ tr = transitions.setdefault(t.id, {})
+ tr['source'] = node.id
+ nodes[node.id] = pool.get('process.node').copy(cr, uid, node.id, context=context)
+
+ # then copy transitions with new nodes
+ for tid, tr in transitions.items():
+ vals = {
+ 'source_node_id': nodes[tr['source']],
+ 'target_node_id': nodes[tr['target']]
+ }
+ tr = pool.get('process.transition').copy(cr, uid, tid, default=vals, context=context)
+
+ # and finally copy the process itself with new nodes
+ default.update({
+ 'active': True,
+ 'node_ids': [(6, 0, nodes.values())]
+ })
+ return super(process_process, self).copy(cr, uid, id, default, context)
process_process()
'note': fields.text('Notes', translate=True),
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
'model_states': fields.char('States Expression', size=128),
+ 'subflow_id': fields.many2one('process.process', 'Subflow', ondelete='set null'),
'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')
+ 'condition_ids': fields.one2many('process.condition', 'node_id', 'Conditions'),
+ 'help_url': fields.char('Help URL', size=255)
}
_defaults = {
'kind': lambda *args: 'state',
'model_states': lambda *args: False,
'flow_start': lambda *args: False,
}
+
+ def copy(self, cr, uid, id, default=None, context={}):
+ if not default:
+ default = {}
+ default.update({
+ 'transition_in': [],
+ 'transition_out': []
+ })
+ return super(process_node, self).copy(cr, uid, id, default, context)
+
process_node()
class process_node_condition(osv.osv):
'target_node_id': fields.many2one('process.node', 'Target Node', required=True, ondelete='cascade'),
'action_ids': fields.one2many('process.transition.action', 'transition_id', 'Buttons'),
'transition_ids': fields.many2many('workflow.transition', 'process_transition_ids', 'ptr_id', 'wtr_id', 'Workflow Transitions'),
+ 'role_ids': fields.many2many('res.roles', 'process_transition_roles_rel', 'tid', 'rid', 'Roles'),
'note': fields.text('Description', translate=True),
}
process_transition()
_defaults = {
'state': lambda *args: 'dummy',
}
+
+ def copy(self, cr, uid, id, default=None, context={}):
+ if not default:
+ default = {}
+
+ state = self.pool.get('process.transition.action').browse(cr, uid, [id], context)[0].state
+ if state:
+ default['state'] = state
+
+ return super(process_transition_action, self).copy(cr, uid, id, default, context)
+
process_transition_action()