1
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
35
def create(cr, ident, wkf_id):
36
(uid,res_type,res_id) = ident
37
cr.execute("select nextval('wkf_instance_id_seq')")
38
id_new = cr.fetchone()[0]
39
cr.execute('insert into wkf_instance (id,res_type,res_id,uid,wkf_id) values (%d,%s,%s,%s,%s)', (id_new,res_type,res_id,uid,wkf_id))
40
cr.execute('select * from wkf_activity where flow_start=True and wkf_id=%d', (wkf_id,))
41
res = cr.dictfetchall()
42
workitem.create(cr, res, id_new, ident)
43
update(cr, id_new, ident)
46
def delete(cr, ident):
47
(uid,res_type,res_id) = ident
48
cr.execute('delete from wkf_instance where res_id=%d and res_type=%s', (res_id,res_type))
50
def validate(cr, inst_id, ident, signal, force_running=False):
51
cr.execute("select * from wkf_workitem where inst_id=%d", (inst_id,))
52
for witem in cr.dictfetchall():
53
workitem.process(cr, witem, ident, signal, force_running)
54
return _update_end(cr, inst_id, ident)
56
def update(cr, inst_id, ident):
57
cr.execute("select * from wkf_workitem where inst_id=%d", (inst_id,))
58
for witem in cr.dictfetchall():
59
workitem.process(cr, witem, ident)
60
return _update_end(cr, inst_id, ident)
62
def _update_end(cr, inst_id, ident):
63
cr.execute('select wkf_id from wkf_instance where id=%d', (inst_id,))
64
wkf_id = cr.fetchone()[0]
65
cr.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,))
67
for r in cr.fetchall():
68
if (r[0]<>'complete') or not r[1]:
72
cr.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,))
73
act_names = cr.fetchall()
74
cr.execute("update wkf_instance set state='complete' where id=%d", (inst_id,))
75
cr.execute("update wkf_workitem set state='complete' where subflow_id=%d", (inst_id,))
76
cr.execute("select i.id,w.osv,i.res_id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where i.id in (select inst_id from wkf_workitem where subflow_id=%d)", (inst_id,))
77
for i in cr.fetchall():
78
for act_name in act_names:
79
validate(cr, i[0], (ident[0],i[1],i[2]), 'subflow.'+act_name[0])