1 ##############################################################################
3 # Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 # $Id: wkf_expr.py 1304 2005-09-08 14:35:42Z nicoe $
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
35 class EnvCall(object):
37 def __init__(self,wf_service,d_arg):
38 self.wf_service=wf_service
41 def __call__(self,*args):
43 return self.wf_service.execute_cr(*arg)
48 def __init__(self, wf_service, cr, uid, model, ids):
49 self.wf_service = wf_service
54 self.obj = pooler.get_pool(cr.dbname).get(model)
55 self.columns = self.obj._columns.keys() + self.obj._inherit_fields.keys()
57 def __getitem__(self, key):
58 if (key in self.columns) and (not super(Env, self).__contains__(key)):
59 res=self.wf_service.execute_cr(self.cr, self.uid, self.model, 'read',\
60 self.ids, [key])[0][key]
61 super(Env, self).__setitem__(key, res)
63 elif key in dir(self.obj):
64 return EnvCall(self.wf_service, (self.cr, self.uid, self.model, key,\
67 return super(Env, self).__getitem__(key)
70 def _eval_expr(cr, ident, workitem, action):
72 for line in action.split('\n'):
81 wf_service = netsvc.LocalService("object_proxy")
82 env = Env(wf_service, cr, uid, model, ids)
86 def execute(cr, ident, workitem, activity):
87 return _eval_expr(cr, ident, workitem, activity['action'])
89 def check(cr, workitem, ident, transition, signal):
91 if transition['signal']:
92 ok = (signal==transition['signal'])
94 if transition['role_id']:
96 serv = netsvc.LocalService('object_proxy')
97 user_roles = serv.execute_cr(cr, uid, 'res.users', 'read', [uid], ['roles_id'])[0]['roles_id']
98 ok = ok and serv.execute_cr(cr, uid, 'res.roles', 'check', user_roles, transition['role_id'])
99 ok = ok and _eval_expr(cr, ident, workitem, transition['condition'])