[IMP] workflow: add sequence for ordering workflow transitions (split/join mode especially for XOR)

Makes ordering transitions easier and more deterministic.

(Rebase of #1564)
This commit is contained in:
Wolfgang Taferner 2014-08-04 16:07:25 +02:00 committed by Olivier Dony
parent 973770f7cb
commit b09a766f0a
5 changed files with 13 additions and 5 deletions

View File

@ -111,6 +111,7 @@ class wkf_transition(osv.osv):
_columns = { _columns = {
'trigger_model': fields.char('Trigger Object'), 'trigger_model': fields.char('Trigger Object'),
'trigger_expr_id': fields.char('Trigger Expression'), 'trigger_expr_id': fields.char('Trigger Expression'),
'sequence': fields.integer('Sequence'),
'signal': fields.char('Signal (Button Name)', 'signal': fields.char('Signal (Button Name)',
help="When the operation of transition comes from a button pressed in the client form, "\ 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."), "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 = { _defaults = {
'condition': lambda *a: 'True', 'condition': lambda *a: 'True',
'sequence': 10,
} }
_order = 'sequence,id'
def name_get(self, cr, uid, ids, context=None): 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)] 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)]

View File

@ -70,7 +70,7 @@ def graph_get(cr, graph, wkf_ids, nested, workitem, witm_trans, processed_subflo
actfrom[n['id']] = (n['id'],{}) actfrom[n['id']] = (n['id'],{})
actto[n['id']] = (n['id'],{}) actto[n['id']] = (n['id'],{})
node_ids = tuple(map(itemgetter('id'), nodes)) 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() transitions = cr.dictfetchall()
for t in transitions: for t in transitions:
if not t['act_to'] in activities: if not t['act_to'] in activities:

View File

@ -120,6 +120,7 @@
<page string="Transitions"> <page string="Transitions">
<field name="in_transitions"> <field name="in_transitions">
<tree string="Incoming Transitions"> <tree string="Incoming Transitions">
<field name="sequence" widget="handle" />
<field name="act_from"/> <field name="act_from"/>
<field name="signal"/> <field name="signal"/>
<field name="condition"/> <field name="condition"/>
@ -127,6 +128,7 @@
</field> </field>
<field name="out_transitions"> <field name="out_transitions">
<tree string="Outgoing Transitions"> <tree string="Outgoing Transitions">
<field name="sequence" widget="handle" />
<field name="act_to"/> <field name="act_to"/>
<field name="signal"/> <field name="signal"/>
<field name="condition"/> <field name="condition"/>
@ -196,6 +198,7 @@
<sheet> <sheet>
<group> <group>
<group> <group>
<field name="sequence" />
<field name="act_from"/> <field name="act_from"/>
<field name="act_to"/> <field name="act_to"/>
<field name="signal"/> <field name="signal"/>
@ -216,6 +219,7 @@
<field name="model">workflow.transition</field> <field name="model">workflow.transition</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Transition"> <tree string="Transition">
<field name="sequence" widget="handle" />
<field name="act_from"/> <field name="act_from"/>
<field name="act_to"/> <field name="act_to"/>
<field name="signal"/> <field name="signal"/>

View File

@ -615,7 +615,7 @@ class YamlInterpreter(object):
uid = workflow.uid uid = workflow.uid
else: else:
uid = self.uid 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()] signals=[x['signal'] for x in self.cr.dictfetchall()]
if workflow.action not in signals: if workflow.action not in signals:
raise YamlImportException('Incorrect action %s. No such action defined' % workflow.action) raise YamlImportException('Incorrect action %s. No such action defined' % workflow.action)

View File

@ -121,7 +121,7 @@ class WorkflowItem(object):
triggers = triggers and not ok triggers = triggers and not ok
if triggers: 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(): for trans in cr.dictfetchall():
if trans['trigger_model']: if trans['trigger_model']:
ids = self.wkf_expr_eval_expr(trans['trigger_expr_id']) 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): def _split_test(self, split_mode, signal, stack):
cr = self.session.cr 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 test = False
transitions = [] transitions = []
alltrans = cr.dictfetchall() alltrans = cr.dictfetchall()
@ -257,7 +257,7 @@ class WorkflowItem(object):
WorkflowItem.create(self.session, self.record, activity, inst_id, stack=stack) 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)) cr.execute('delete from wkf_witm_trans where inst_id=%s and trans_id=%s', (inst_id,trans_id))
else: 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() trans_ids = cr.fetchall()
ok = True ok = True
for (id,) in trans_ids: for (id,) in trans_ids: