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 ##############################################################################
22 import openerp.pooler as pooler
23 from openerp.tools.safe_eval import safe_eval as eval
26 def __init__(self, cr, uid, model, ids):
31 self.obj = pooler.get_pool(cr.dbname).get(model)
32 self.columns = self.obj._columns.keys() + self.obj._inherit_fields.keys()
34 def __getitem__(self, key):
35 if (key in self.columns) or (key in dir(self.obj)):
36 res = self.obj.browse(self.cr, self.uid, self.ids[0])
39 return super(Env, self).__getitem__(key)
41 def _eval_expr(cr, ident, workitem, action):
43 assert action, 'You used a NULL action in a workflow, use dummy node instead.'
44 for line in action.split('\n'):
56 env = Env(cr, uid, model, ids)
57 ret = eval(line, env, nocopy=True)
60 def execute_action(cr, ident, workitem, activity):
61 obj = pooler.get_pool(cr.dbname).get('ir.actions.server')
62 ctx = {'active_model':ident[1], 'active_id':ident[2], 'active_ids':[ident[2]]}
63 result = obj.run(cr, ident[0], [activity['action_id']], ctx)
66 def execute(cr, ident, workitem, activity):
67 return _eval_expr(cr, ident, workitem, activity['action'])
69 def check(cr, workitem, ident, transition, signal):
70 if transition['signal'] and signal != transition['signal']:
74 if transition['group_id'] and uid != 1:
75 pool = pooler.get_pool(cr.dbname)
76 user_groups = pool.get('res.users').read(cr, uid, [uid], ['groups_id'])[0]['groups_id']
77 if not transition['group_id'] in user_groups:
80 return _eval_expr(cr, ident, workitem, transition['condition'])
83 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: