1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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 def __init__(self, cr, uid, model, ids):
34 self.obj = pooler.get_pool(cr.dbname).get(model)
35 self.columns = self.obj._columns.keys() + self.obj._inherit_fields.keys()
37 def __getitem__(self, key):
38 if (key in self.columns) or (key in dir(self.obj)):
39 res = self.obj.browse(self.cr, self.uid, self.ids[0])
42 return super(Env, self).__getitem__(key)
44 def _eval_expr(cr, ident, workitem, action):
46 assert action, 'You used a NULL action in a workflow, use dummy node instead.'
47 for line in action.split('\n'):
57 env = Env(cr, uid, model, ids)
61 def execute_action(cr, ident, workitem, activity):
62 obj = pooler.get_pool(cr.dbname).get('ir.actions.server')
63 ctx = {'active_id':ident[2], 'active_ids':[ident[2]]}
64 result = obj.run(cr, ident[0], [activity['action_id']], ctx)
67 def execute(cr, ident, workitem, activity):
68 return _eval_expr(cr, ident, workitem, activity['action'])
70 def check(cr, workitem, ident, transition, signal):
72 if transition['signal']:
73 ok = (signal==transition['signal'])
76 if transition['role_id'] and uid != 1:
77 pool = pooler.get_pool(cr.dbname)
78 user_roles = pool.get('res.users').read(cr, uid, [uid], ['roles_id'])[0]['roles_id']
79 ok = ok and pool.get('res.roles').check(cr, uid, user_roles, transition['role_id'])
80 ok = ok and _eval_expr(cr, ident, workitem, transition['condition'])
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: