diff --git a/trytond/init.sql b/trytond/init.sql index 712e8bd441..a1e2679889 100644 --- a/trytond/init.sql +++ b/trytond/init.sql @@ -137,8 +137,8 @@ create table wkf create table wkf_activity ( id serial, - wkf_id int references wkf on delete cascade, - subflow_id int references wkf on delete set null, + workflow int references wkf on delete cascade, + subflow int references wkf on delete set null, split_mode varchar(3) default 'XOR', join_mode varchar(3) default 'XOR', kind varchar(16) not null default 'dummy', @@ -169,7 +169,7 @@ create table wkf_transition create table wkf_instance ( id serial, - wkf_id int references wkf on delete restrict, + workflow int references wkf on delete restrict, uid int default null, res_id int not null, res_type varchar(64) not null, @@ -180,9 +180,9 @@ create table wkf_instance create table wkf_workitem ( id serial, - act_id int not null references wkf_activity on delete cascade, - inst_id int not null references wkf_instance on delete cascade, - subflow_id int references wkf_instance on delete cascade, + activity int not null references wkf_activity on delete cascade, + instance int not null references wkf_instance on delete cascade, + subflow int references wkf_instance on delete cascade, state varchar(64) default 'blocked', primary key(id) ); @@ -199,7 +199,7 @@ create table wkf_logs res_type varchar(128) not null, res_id int not null, uid int references res_user on delete set null, - act_id int references wkf_activity on delete set null, + activity int references wkf_activity on delete set null, time time not null, info varchar(128) default NULL, primary key(id) diff --git a/trytond/ir/model.py b/trytond/ir/model.py index aa5a0de20e..29efab1803 100644 --- a/trytond/ir/model.py +++ b/trytond/ir/model.py @@ -388,7 +388,7 @@ class ModelData(OSV): cursor.execute('SELECT res_type, db_id ' \ 'FROM wkf_instance ' \ 'WHERE id IN (' \ - 'SELECT inst_id FROM wkf_workitem ' \ + 'SELECT instance FROM wkf_workitem ' \ 'WHERE act_id = %d)', (db_id,)) wkf_todo.extend(cursor.fetchall()) cursor.execute("UPDATE wkf_transition " \ diff --git a/trytond/wkf_service/instance.py b/trytond/wkf_service/instance.py index dd797ab854..42766028eb 100644 --- a/trytond/wkf_service/instance.py +++ b/trytond/wkf_service/instance.py @@ -5,10 +5,10 @@ def create(cursor, ident, wkf_id): cursor.execute("SELECT NEXTVAL('wkf_instance_id_seq')") (id_new,) = cursor.fetchone() cursor.execute('INSERT INTO wkf_instance ' \ - '(id, res_type, res_id, uid, wkf_id) VALUES (%d,%s,%s,%s,%s)', + '(id, res_type, res_id, uid, workflow) VALUES (%d,%s,%s,%s,%s)', (id_new, res_type, res_id, user, wkf_id)) cursor.execute('SELECT * FROM wkf_activity ' \ - 'WHERE flow_start = True and wkf_id = %d', (wkf_id,)) + 'WHERE flow_start = True and workflow = %d', (wkf_id,)) res = cursor.dictfetchall() workitem.create(cursor, res, id_new, ident) update(cursor, id_new, ident) @@ -20,13 +20,15 @@ def delete(cursor, ident): 'WHERE res_id = %d AND res_type = %s', (res_id, res_type)) def validate(cursor, inst_id, ident, signal, force_running=False): - cursor.execute("SELECT * FROM wkf_workitem WHERE inst_id = %d", (inst_id,)) + cursor.execute("SELECT * FROM wkf_workitem WHERE instance = %d", + (inst_id,)) for witem in cursor.dictfetchall(): workitem.process(cursor, witem, ident, signal, force_running) return _update_end(cursor, inst_id, ident) def update(cursor, inst_id, ident): - cursor.execute("SELECT * FROM wkf_workitem WHERE inst_id = %d", (inst_id,)) + cursor.execute("SELECT * FROM wkf_workitem WHERE instance = %d", + (inst_id,)) for witem in cursor.dictfetchall(): workitem.process(cursor, witem, ident) return _update_end(cursor, inst_id, ident) @@ -34,7 +36,8 @@ def update(cursor, inst_id, ident): def _update_end(cursor, inst_id, ident): cursor.execute('SELECT state, flow_stop FROM wkf_workitem w ' \ 'LEFT JOIN wkf_activity a ' \ - 'ON (a.id = w.act_id) WHERE w.inst_id = %d', (inst_id,)) + 'ON (a.id = w.activity) WHERE w.instance = %d', + (inst_id,)) res = True for row in cursor.fetchall(): if (row[0] != 'complete') or not row[1]: @@ -43,20 +46,20 @@ def _update_end(cursor, inst_id, ident): if res: cursor.execute('SELECT DISTINCT a.name FROM wkf_activity a ' \ 'LEFT JOIN wkf_workitem w ' \ - 'ON (a.id = w.act_id) ' \ - 'WHERE w.inst_id = %d', (inst_id,)) + 'ON (a.id = w.activity) ' \ + 'WHERE w.instance = %d', (inst_id,)) act_names = cursor.fetchall() cursor.execute("UPDATE wkf_instance " \ "SET state = 'complete' WHERE id = %d", (inst_id,)) cursor.execute("UPDATE wkf_workitem " \ - "SET state = 'complete' WHERE subflow_id = %d", (inst_id,)) + "SET state = 'complete' WHERE subflow = %d", (inst_id,)) # TODO remove the subquery cursor.execute("SELECT i.id, w.osv, i.res_id " \ "FROM wkf_instance i " \ - "LEFT JOIN wkf w ON (i.wkf_id = w.id) " \ + "LEFT JOIN wkf w ON (i.workflow = w.id) " \ "WHERE i.id IN (" \ - "SELECT inst_id FROM wkf_workitem " \ - "WHERE subflow_id = %d)", (inst_id,)) + "SELECT instance FROM wkf_workitem " \ + "WHERE subflow = %d)", (inst_id,)) for i in cursor.fetchall(): for act_name in act_names: validate(cursor, i[0], (ident[0], i[1], i[2]), diff --git a/trytond/wkf_service/wkf_service.py b/trytond/wkf_service/wkf_service.py index a38413d6ce..49fa728fdf 100644 --- a/trytond/wkf_service/wkf_service.py +++ b/trytond/wkf_service/wkf_service.py @@ -80,7 +80,7 @@ class WorkflowService(Service): """ # get ids of wkf instances for the old resource (res_id) # XXX shouldn't we get only active instances? - cursor.execute('SELECT id, wkf_id FROM wkf_instance ' \ + cursor.execute('SELECT id, workflow FROM wkf_instance ' \ 'WHERE res_id = %d AND res_type = %s', (res_id, res_type)) for old_inst_id, wkf_id in cursor.fetchall(): # first active instance for new resource (new_rid), using same wkf @@ -88,16 +88,16 @@ class WorkflowService(Service): 'SELECT id '\ 'FROM wkf_instance '\ 'WHERE res_id = %d AND res_type = %s ' \ - 'AND wkf_id = %d AND state = %s', + 'AND workflow = %d AND state = %s', (new_rid, res_type, wkf_id, 'active')) new_id = cursor.fetchone() if new_id: # select all workitems which "wait" for the old instance cursor.execute('SELECT id FROM wkf_workitem ' \ - 'WHERE subflow_id = %d', (old_inst_id,)) + 'WHERE subflow = %d', (old_inst_id,)) for (item_id,) in cursor.fetchall(): # redirect all those workitems # to the wkf instance of the new resource cursor.execute('UPDATE wkf_workitem ' \ - 'SET subflow_id = %d ' \ + 'SET subflow = %d ' \ 'WHERE id = %d', (new_id[0], item_id)) diff --git a/trytond/wkf_service/workitem.py b/trytond/wkf_service/workitem.py index 8e45dd027d..093d1949bb 100644 --- a/trytond/wkf_service/workitem.py +++ b/trytond/wkf_service/workitem.py @@ -8,7 +8,7 @@ def create(cursor, act_datas, inst_id, ident): cursor.execute("SELECT NEXTVAL('wkf_workitem_id_seq')") (id_new,) = cursor.fetchone() cursor.execute("INSERT INTO wkf_workitem " \ - "(id, act_id, inst_id, state) VALUES (%d, %s, %s, 'active')", + "(id, activity, instance, state) VALUES (%d, %s, %s, 'active')", (id_new, act['id'], inst_id)) cursor.execute('SELECT * FROM wkf_workitem WHERE id=%d', (id_new,)) res = cursor.dictfetchone() @@ -16,7 +16,7 @@ def create(cursor, act_datas, inst_id, ident): def process(cursor, workitem, ident, signal=None, force_running=False): cursor.execute('SELECT * FROM wkf_activity WHERE id = %d', - (workitem['act_id'],)) + (workitem['activity'],)) activity = cursor.dictfetchone() triggers = False if workitem['state'] == 'active': @@ -34,7 +34,7 @@ def process(cursor, workitem, ident, signal=None, force_running=False): if triggers: cursor.execute('SELECT * FROM wkf_transition ' \ - 'WHERE act_from = %d', (workitem['act_id'],)) + 'WHERE act_from = %d', (workitem['activity'],)) alltrans = cursor.dictfetchall() for trans in alltrans: if trans['trigger_model']: @@ -44,7 +44,7 @@ def process(cursor, workitem, ident, signal=None, force_running=False): cursor.execute('SELECT NEXTVAL(\'wkf_triggers_id_seq\')') (new_id,) = cursor.fetchone() cursor.execute('INSERT INTO wkf_triggers ' \ - '(model, res_id, instance_id, workitem_id, id) ' \ + '(model, res_id, instance, workitem, id) ' \ 'VALUES (%s, %d, %d, %d, %d)', (trans['trigger_model'], res_id, workitem['inst_id'], workitem['id'], new_id)) @@ -63,10 +63,10 @@ def _execute(cursor, workitem, activity, ident): cursor.execute("SELECT i.id, w.osv, i.res_id " \ "FROM wkf_instance i " \ "LEFT JOIN wkf w " \ - "ON (i.wkf_id = w.id) " \ + "ON (i.workflow = w.id) " \ "WHERE i.id in (" \ - "SELECT inst_id FROM wkf_workitem " \ - "WHERE subflow_id = %d)", (workitem['inst_id'],)) + "SELECT instance FROM wkf_workitem " \ + "WHERE subflow = %d)", (workitem['inst_id'],)) for i in cursor.fetchall(): instance.validate(cursor, i[0], (ident[0], i[1], i[2]), activity['signal_send'], force_running=True) @@ -82,8 +82,8 @@ def _execute(cursor, workitem, activity, ident): elif activity['kind'] == 'stopall': if workitem['state'] == 'active': _state_set(cursor, workitem, 'running') - cursor.execute('DELECT FROM wkf_workitem ' \ - 'WHERE inst_id = %d AND id <> %d', + cursor.execute('DELETE FROM wkf_workitem ' \ + 'WHERE instance = %d AND id <> %d', (workitem['inst_id'], workitem['id'])) if activity['action']: wkf_expr.execute(cursor, ident, workitem, activity) @@ -101,13 +101,13 @@ def _execute(cursor, workitem, activity, ident): 'Wrong return value: ' + str(id_new) + ' ' + \ str(type(id_new)) cursor.execute('SELECT id FROM wkf_instance ' \ - 'WHERE res_id = %d AND wkf_id = %d', + 'WHERE res_id = %d AND workflow = %d', (id_new, activity['subflow_id'])) (id_new,) = cursor.fetchone() else: id_new = instance.create(cursor, ident, activity['subflow_id']) cursor.execute('UPDATE wkf_workitem ' \ - 'SET subflow_id = %d WHERE id = %d', + 'SET subflow = %d WHERE id = %d', (id_new, workitem['id'])) workitem['subflow_id'] = id_new if workitem['state'] == 'running': @@ -122,7 +122,7 @@ def _split_test(cursor, workitem, split_mode, ident, signal=None): test = False transitions = [] cursor.execute('SELECT * FROM wkf_transition ' \ - 'WHERE act_from = %d', (workitem['act_id'],)) + 'WHERE act_from = %d', (workitem['activity'],)) alltrans = cursor.dictfetchall() if split_mode == 'XOR' or split_mode == 'OR': for transition in alltrans: diff --git a/trytond/workflow/workflow.py b/trytond/workflow/workflow.py index f545be7022..316bdc3e4c 100644 --- a/trytond/workflow/workflow.py +++ b/trytond/workflow/workflow.py @@ -13,10 +13,10 @@ class Workflow(OSV): _log_access = False _description = __doc__ _columns = { - 'name': fields.char('Name', size=64, required=True), - 'osv': fields.char('Resource Model', size=64, required=True), - 'on_create': fields.boolean('On Create'), - 'activities': fields.one2many('workflow.activity', 'wkf_id', + 'name': fields.Char('Name', size=64, required=True), + 'osv': fields.Char('Resource Model', size=64, required=True), + 'on_create': fields.Boolean('On Create'), + 'activities': fields.One2Many('workflow.activity', 'workflow', 'Activities'), } _defaults = { @@ -45,32 +45,32 @@ class WorkflowActivity(OSV): _log_access = False _description = __doc__ _columns = { - 'name': fields.char('Name', size=64, required=True), - 'wkf_id': fields.many2one('workflow', 'Workflow', required=True, + 'name': fields.Char('Name', size=64, required=True), + 'workflow': fields.Many2One('workflow', 'Workflow', required=True, select=1, ondelete='cascade'), - 'split_mode': fields.selection([ + 'split_mode': fields.Selection([ ('XOR', 'Xor'), ('OR', 'Or'), ('AND', 'And'), ], 'Split Mode', size=3, required=True), - 'join_mode': fields.selection([ + 'join_mode': fields.Selection([ ('XOR', 'Xor'), ('AND', 'And'), ], 'Join Mode', size=3, required=True), - 'kind': fields.selection([ + 'kind': fields.Selection([ ('dummy', 'Dummy'), ('function', 'Function'), ('subflow', 'Subflow'), ('stopall', 'Stop All'), ], 'Kind', size=64, required=True), - 'action': fields.char('Action', size=64), - 'flow_start': fields.boolean('Flow Start'), - 'flow_stop': fields.boolean('Flow Stop'), - 'subflow_id': fields.many2one('workflow', 'Subflow'), - 'signal_send': fields.char('Signal (subflow.*)', size=32), - 'out_transitions': fields.one2many('workflow.transition', 'act_from', + 'action': fields.Char('Action', size=64), + 'flow_start': fields.Boolean('Flow Start'), + 'flow_stop': fields.Boolean('Flow Stop'), + 'subflow': fields.Many2One('workflow', 'Subflow'), + 'signal_send': fields.Char('Signal (subflow.*)', size=32), + 'out_transitions': fields.One2Many('workflow.transition', 'act_from', 'Outgoing transitions'), - 'in_transitions': fields.one2many('workflow.transition', 'act_to', + 'in_transitions': fields.One2Many('workflow.transition', 'act_to', 'Incoming transitions'), } _defaults = { @@ -90,14 +90,14 @@ class WorkflowTransition(OSV): _rec_name = 'signal' _description = __doc__ _columns = { - 'trigger_model': fields.char('Trigger Type', size=128), - 'trigger_expr_id': fields.char('Trigger Expr ID', size=128), - 'signal': fields.char('Signal (button Name)', size=64), - 'group': fields.many2one('res.group', 'Group Required'), - 'condition': fields.char('Condition', required=True, size=128), - 'act_from': fields.many2one('workflow.activity', 'Source Activity', + 'trigger_model': fields.Char('Trigger Type', size=128), + 'trigger_expr_id': fields.Char('Trigger Expr ID', size=128), + 'signal': fields.Char('Signal (button Name)', size=64), + 'group': fields.Many2One('res.group', 'Group Required'), + 'condition': fields.Char('Condition', required=True, size=128), + 'act_from': fields.Many2One('workflow.activity', 'Source Activity', required=True, select=1, ondelete='cascade'), - 'act_to': fields.many2one('workflow.activity', 'Destination Activity', + 'act_to': fields.Many2One('workflow.activity', 'Destination Activity', required=True, select=1, ondelete='cascade'), } _defaults = { @@ -115,11 +115,11 @@ class WorkflowInstance(OSV): _log_access = False _description = __doc__ _columns = { - 'wkf_id': fields.many2one('workflow', 'Workflow', ondelete="restrict"), - 'uid': fields.integer('User ID'), - 'res_id': fields.integer('Resource ID'), - 'res_type': fields.char('Resource Model', size=64), - 'state': fields.char('State', size=32), + 'workflow': fields.Many2One('workflow', 'Workflow', ondelete="restrict"), + 'uid': fields.Integer('User ID'), + 'res_id': fields.Integer('Resource ID'), + 'res_type': fields.Char('Resource Model', size=64), + 'state': fields.Char('State', size=32), } def _auto_init(self, cursor, module_name): @@ -144,13 +144,13 @@ class WorkflowWorkitem(OSV): _rec_name = 'state' _description = __doc__ _columns = { - 'act_id': fields.many2one('workflow.activity', 'Activity', + 'activity': fields.Many2One('workflow.activity', 'Activity', required=True, ondelete="cascade"), - 'subflow_id': fields.many2one('workflow.instance', 'Subflow', + 'subflow': fields.Many2One('workflow.instance', 'Subflow', ondelete="cascade"), - 'inst_id': fields.many2one('workflow.instance', 'Instance', + 'instance': fields.Many2One('workflow.instance', 'Instance', required=True, ondelete="cascade", select=1), - 'state': fields.char('State', size=64), + 'state': fields.Char('State', size=64), } WorkflowWorkitem() @@ -163,11 +163,11 @@ class WorkflowTrigger(OSV): _log_access = False _description = __doc__ _columns = { - 'res_id': fields.integer('Resource ID', size=128), - 'model': fields.char('Model', size=128), - 'instance_id': fields.many2one('workflow.instance', + 'res_id': fields.Integer('Resource ID', size=128), + 'model': fields.Char('Model', size=128), + 'instance': fields.Many2One('workflow.instance', 'Destination Instance', ondelete="cascade"), - 'workitem_id': fields.many2one('workflow.workitem', 'Workitem', + 'workitem': fields.Many2One('workflow.workitem', 'Workitem', required=True, ondelete="cascade"), } @@ -200,7 +200,7 @@ class InstanceGraph(Report): context=context) instance_id = instance_obj.search(cursor, user, [ ('res_id', '=', datas['id']), - ('wkf_id', '=', workflow.id), + ('workflow', '=', workflow.id), ], limit=1, context=context) if not instance_id: raise ExceptOSV('UserError', 'No workflow instance defined!') @@ -235,7 +235,7 @@ class InstanceGraph(Report): instance_obj = self.pool.get('workflow.instance') instance = instance_obj.browse(cursor, user, instance_id, context=context) - self.graph_get(cursor, user, graph, instance.wkf_id.id, nested, + self.graph_get(cursor, user, graph, instance.workflow.id, nested, self.workitem_get(cursor, user, instance.id, context=context), context=context) @@ -243,16 +243,16 @@ class InstanceGraph(Report): res = {} workitem_obj = self.pool.get('workflow.workitem') workitem_ids = workitem_obj.search(cursor, user, [ - ('inst_id', '=', instance_id), + ('instance', '=', instance_id), ], context=context) workitems = workitem_obj.browse(cursor, user, workitem_ids, context=context) for workitem in workitems: - res.setdefault(workitem.act_id.id, 0) - res[workitem.act_id.id] += 1 - if workitem.subflow_id: + res.setdefault(workitem.activity.id, 0) + res[workitem.activity.id] += 1 + if workitem.subflow: res.update(self.workitem_get(cursor, user, - workitem.subflow_id.id, context=context)) + workitem.subflow.id, context=context)) return res def graph_get(self, cursor, user, graph, workflow_id, nested=False, @@ -264,7 +264,7 @@ class InstanceGraph(Report): workflow_obj = self.pool.get('workflow') transition_obj = self.pool.get('workflow.transition') activity_ids = activity_obj.search(cursor, user, [ - ('wkf_id', '=', workflow_id), + ('workflow', '=', workflow_id), ], context=context) id2activities = {} actfrom = {} @@ -279,9 +279,9 @@ class InstanceGraph(Report): if activity.flow_stop: stop['subflow.' + activity.name] = activity.id id2activities[activity.id] = activity - if activity.subflow_id and nested: + if activity.subflow and nested: workflow = workflow_obj.browse(cursor, user, - activity.subflow_id.id, context=context) + activity.subflow.id, context=context) subgraph = pydot.Cluster('subflow' + str(workflow.id), fontsize=12, label="Subflow: " + activity.name + \ '\\nOSV: ' + workflow.osv) @@ -297,7 +297,7 @@ class InstanceGraph(Report): args['style'] = 'filled' args['color'] = 'lightgrey' args['label'] = activity.name - if activity.subflow_id: + if activity.subflow: args['shape'] = 'box' if activity.id in workitem: args['label'] += '\\nx ' + str(workitem[activity.id]) diff --git a/trytond/workflow/workflow.xml b/trytond/workflow/workflow.xml index 46258cd1dd..aae787887d 100644 --- a/trytond/workflow/workflow.xml +++ b/trytond/workflow/workflow.xml @@ -60,14 +60,14 @@
@@ -308,9 +308,9 @@