From b09a766f0aa1c012048fa3977e34c460fa1f2cf1 Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Mon, 4 Aug 2014 16:07:25 +0200 Subject: [PATCH] [IMP] workflow: add sequence for ordering workflow transitions (split/join mode especially for XOR) Makes ordering transitions easier and more deterministic. (Rebase of #1564) --- openerp/addons/base/workflow/workflow.py | 4 ++++ openerp/addons/base/workflow/workflow_report.py | 2 +- openerp/addons/base/workflow/workflow_view.xml | 4 ++++ openerp/tools/yaml_import.py | 2 +- openerp/workflow/workitem.py | 6 +++--- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/workflow/workflow.py b/openerp/addons/base/workflow/workflow.py index ee2525b017a..75301a6e4ec 100644 --- a/openerp/addons/base/workflow/workflow.py +++ b/openerp/addons/base/workflow/workflow.py @@ -111,6 +111,7 @@ class wkf_transition(osv.osv): _columns = { 'trigger_model': fields.char('Trigger Object'), 'trigger_expr_id': fields.char('Trigger Expression'), + 'sequence': fields.integer('Sequence'), 'signal': fields.char('Signal (Button Name)', help="When the operation of transition comes from a button pressed in the client form, "\ "signal tests the name of the pressed button. If signal is NULL, no button is necessary to validate this transition."), @@ -126,8 +127,11 @@ class wkf_transition(osv.osv): } _defaults = { 'condition': lambda *a: 'True', + 'sequence': 10, } + _order = 'sequence,id' + def name_get(self, cr, uid, ids, context=None): return [(line.id, (line.act_from.name) + '+' + (line.act_to.name)) if line.signal == False else (line.id, line.signal) for line in self.browse(cr, uid, ids, context=context)] diff --git a/openerp/addons/base/workflow/workflow_report.py b/openerp/addons/base/workflow/workflow_report.py index 5e948d98db6..64339afeaf1 100644 --- a/openerp/addons/base/workflow/workflow_report.py +++ b/openerp/addons/base/workflow/workflow_report.py @@ -70,7 +70,7 @@ def graph_get(cr, graph, wkf_ids, nested, workitem, witm_trans, processed_subflo actfrom[n['id']] = (n['id'],{}) actto[n['id']] = (n['id'],{}) node_ids = tuple(map(itemgetter('id'), nodes)) - cr.execute('select * from wkf_transition where act_from IN %s', (node_ids,)) + cr.execute('select * from wkf_transition where act_from IN %s ORDER BY sequence,id', (node_ids,)) transitions = cr.dictfetchall() for t in transitions: if not t['act_to'] in activities: diff --git a/openerp/addons/base/workflow/workflow_view.xml b/openerp/addons/base/workflow/workflow_view.xml index 23ca704cff0..f67e3996feb 100644 --- a/openerp/addons/base/workflow/workflow_view.xml +++ b/openerp/addons/base/workflow/workflow_view.xml @@ -120,6 +120,7 @@ + @@ -127,6 +128,7 @@ + @@ -196,6 +198,7 @@ + @@ -216,6 +219,7 @@ workflow.transition + diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index a041cf511be..2a56ffeb0bc 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -615,7 +615,7 @@ class YamlInterpreter(object): uid = workflow.uid else: uid = self.uid - self.cr.execute('select distinct signal from wkf_transition') + self.cr.execute('select distinct signal, sequence, id from wkf_transition ORDER BY sequence,id') signals=[x['signal'] for x in self.cr.dictfetchall()] if workflow.action not in signals: raise YamlImportException('Incorrect action %s. No such action defined' % workflow.action) diff --git a/openerp/workflow/workitem.py b/openerp/workflow/workitem.py index 1c08788257e..29d3294dc0f 100644 --- a/openerp/workflow/workitem.py +++ b/openerp/workflow/workitem.py @@ -121,7 +121,7 @@ class WorkflowItem(object): triggers = triggers and not ok if triggers: - cr.execute('select * from wkf_transition where act_from=%s', (self.workitem['act_id'],)) + cr.execute('select * from wkf_transition where act_from=%s ORDER BY sequence,id', (self.workitem['act_id'],)) for trans in cr.dictfetchall(): if trans['trigger_model']: ids = self.wkf_expr_eval_expr(trans['trigger_expr_id']) @@ -219,7 +219,7 @@ class WorkflowItem(object): def _split_test(self, split_mode, signal, stack): cr = self.session.cr - cr.execute('select * from wkf_transition where act_from=%s', (self.workitem['act_id'],)) + cr.execute('select * from wkf_transition where act_from=%s ORDER BY sequence,id', (self.workitem['act_id'],)) test = False transitions = [] alltrans = cr.dictfetchall() @@ -257,7 +257,7 @@ class WorkflowItem(object): WorkflowItem.create(self.session, self.record, activity, inst_id, stack=stack) cr.execute('delete from wkf_witm_trans where inst_id=%s and trans_id=%s', (inst_id,trans_id)) else: - cr.execute('select id from wkf_transition where act_to=%s', (activity['id'],)) + cr.execute('select id from wkf_transition where act_to=%s ORDER BY sequence,id', (activity['id'],)) trans_ids = cr.fetchall() ok = True for (id,) in trans_ids: