1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
28 def create(cr, ident, wkf_id):
29 (uid,res_type,res_id) = ident
30 cr.execute("select nextval('wkf_instance_id_seq')")
31 id_new = cr.fetchone()[0]
32 cr.execute('insert into wkf_instance (id,res_type,res_id,uid,wkf_id) values (%s,%s,%s,%s,%s)', (id_new,res_type,res_id,uid,wkf_id))
33 cr.execute('select * from wkf_activity where flow_start=True and wkf_id=%s', (wkf_id,))
34 res = cr.dictfetchall()
36 workitem.create(cr, res, id_new, ident, stack=stack)
37 update(cr, id_new, ident)
40 def delete(cr, ident):
41 (uid,res_type,res_id) = ident
42 cr.execute('delete from wkf_instance where res_id=%s and res_type=%s', (res_id,res_type))
44 def validate(cr, inst_id, ident, signal, force_running=False):
45 cr.execute("select * from wkf_workitem where inst_id=%s", (inst_id,))
47 for witem in cr.dictfetchall():
49 workitem.process(cr, witem, ident, signal, force_running, stack=stack)
50 # An action is returned
51 _update_end(cr, inst_id, ident)
52 return stack and stack[0] or False
54 def update(cr, inst_id, ident):
55 cr.execute("select * from wkf_workitem where inst_id=%s", (inst_id,))
56 for witem in cr.dictfetchall():
58 workitem.process(cr, witem, ident, stack=stack)
59 return _update_end(cr, inst_id, ident)
61 def _update_end(cr, inst_id, ident):
62 cr.execute('select wkf_id from wkf_instance where id=%s', (inst_id,))
63 wkf_id = cr.fetchone()[0]
64 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=%s', (inst_id,))
66 for r in cr.fetchall():
67 if (r[0]<>'complete') or not r[1]:
71 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=%s', (inst_id,))
72 act_names = cr.fetchall()
73 cr.execute("update wkf_instance set state='complete' where id=%s", (inst_id,))
74 cr.execute("update wkf_workitem set state='complete' where subflow_id=%s", (inst_id,))
75 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=%s)", (inst_id,))
76 for i in cr.fetchall():
77 for act_name in act_names:
78 validate(cr, i[0], (ident[0],i[1],i[2]), 'subflow.'+act_name[0])
82 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: