1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
29 class EnvCall(object):
31 def __init__(self,wf_service,d_arg):
32 self.wf_service=wf_service
35 def __call__(self,*args):
37 return self.wf_service.execute_cr(*arg)
42 def __init__(self, wf_service, cr, uid, model, ids):
43 self.wf_service = wf_service
48 self.obj = pooler.get_pool(cr.dbname).get(model)
49 self.columns = self.obj._columns.keys() + self.obj._inherit_fields.keys()
51 def __getitem__(self, key):
52 if (key in self.columns) or (key in dir(self.obj)):
53 res = self.obj.browse(self.cr, self.uid, self.ids[0])
55 #res=self.wf_service.execute_cr(self.cr, self.uid, self.model, 'read',\
56 # self.ids, [key])[0][key]
57 #super(Env, self).__setitem__(key, res)
59 #elif key in dir(self.obj):
60 # return EnvCall(self.wf_service, (self.cr, self.uid, self.model, key,\
63 return super(Env, self).__getitem__(key)
65 def _eval_expr(cr, ident, workitem, action):
67 assert action, 'You used a NULL action in a workflow, use dummy node instead.'
68 for line in action.split('\n'):
69 line = line.replace(chr(13),'')
78 wf_service = netsvc.LocalService("object_proxy")
79 env = Env(wf_service, cr, uid, model, ids)
83 def execute_action(cr, ident, workitem, activity):
84 wf_service = netsvc.LocalService("object_proxy")
85 obj = pooler.get_pool(cr.dbname).get('ir.actions.server')
86 ctx = {'active_id':ident[2], 'active_ids':[ident[2]]}
87 result = obj.run(cr, ident[0], [activity['action_id']], ctx)
90 def execute(cr, ident, workitem, activity):
91 return _eval_expr(cr, ident, workitem, activity['action'])
93 def check(cr, workitem, ident, transition, signal):
95 if transition['signal']:
96 ok = (signal==transition['signal'])
99 if transition['role_id'] and uid != 1:
100 serv = netsvc.LocalService('object_proxy')
101 user_roles = serv.execute_cr(cr, uid, 'res.users', 'read', [uid], ['roles_id'])[0]['roles_id']
102 ok = ok and serv.execute_cr(cr, uid, 'res.roles', 'check', user_roles, transition['role_id'])
103 ok = ok and _eval_expr(cr, ident, workitem, transition['condition'])
107 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: