2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-10-14 12:32:15 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
##############################################################################
|
2008-06-16 07:24:04 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
import sys
|
2011-02-07 12:57:23 +00:00
|
|
|
import openerp.netsvc as netsvc
|
|
|
|
import openerp.osv as base
|
|
|
|
import openerp.pooler as pooler
|
|
|
|
from openerp.tools.safe_eval import safe_eval as eval
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2007-07-26 08:32:07 +00:00
|
|
|
class Env(dict):
|
2009-01-02 23:18:51 +00:00
|
|
|
def __init__(self, cr, uid, model, ids):
|
2008-07-22 14:24:36 +00:00
|
|
|
self.cr = cr
|
|
|
|
self.uid = uid
|
|
|
|
self.model = model
|
|
|
|
self.ids = ids
|
|
|
|
self.obj = pooler.get_pool(cr.dbname).get(model)
|
|
|
|
self.columns = self.obj._columns.keys() + self.obj._inherit_fields.keys()
|
2007-07-26 08:32:07 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
def __getitem__(self, key):
|
|
|
|
if (key in self.columns) or (key in dir(self.obj)):
|
|
|
|
res = self.obj.browse(self.cr, self.uid, self.ids[0])
|
|
|
|
return res[key]
|
|
|
|
else:
|
|
|
|
return super(Env, self).__getitem__(key)
|
2007-07-26 08:32:07 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
def _eval_expr(cr, ident, workitem, action):
|
2008-07-22 14:24:36 +00:00
|
|
|
ret=False
|
|
|
|
assert action, 'You used a NULL action in a workflow, use dummy node instead.'
|
|
|
|
for line in action.split('\n'):
|
2008-12-12 10:58:04 +00:00
|
|
|
line = line.strip()
|
2008-07-22 14:24:36 +00:00
|
|
|
uid=ident[0]
|
|
|
|
model=ident[1]
|
|
|
|
ids=[ident[2]]
|
|
|
|
if line =='True':
|
|
|
|
ret=True
|
|
|
|
elif line =='False':
|
|
|
|
ret=False
|
|
|
|
else:
|
2009-01-02 23:18:51 +00:00
|
|
|
env = Env(cr, uid, model, ids)
|
2010-06-04 00:39:40 +00:00
|
|
|
ret = eval(line, env, nocopy=True)
|
2008-07-22 14:24:36 +00:00
|
|
|
return ret
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-06-15 00:25:47 +00:00
|
|
|
def execute_action(cr, ident, workitem, activity):
|
2008-07-22 14:24:36 +00:00
|
|
|
obj = pooler.get_pool(cr.dbname).get('ir.actions.server')
|
2011-09-14 10:25:05 +00:00
|
|
|
ctx = {'active_model':ident[1], 'active_id':ident[2], 'active_ids':[ident[2]]}
|
2008-07-22 14:24:36 +00:00
|
|
|
result = obj.run(cr, ident[0], [activity['action_id']], ctx)
|
|
|
|
return result
|
2008-06-15 00:25:47 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
def execute(cr, ident, workitem, activity):
|
2008-07-22 14:24:36 +00:00
|
|
|
return _eval_expr(cr, ident, workitem, activity['action'])
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
def check(cr, workitem, ident, transition, signal):
|
2010-10-13 21:53:40 +00:00
|
|
|
if transition['signal'] and signal != transition['signal']:
|
|
|
|
return False
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-10-27 12:54:13 +00:00
|
|
|
uid = ident[0]
|
2010-10-13 21:53:40 +00:00
|
|
|
if transition['group_id'] and uid != 1:
|
2009-01-02 23:18:51 +00:00
|
|
|
pool = pooler.get_pool(cr.dbname)
|
2010-10-13 21:53:40 +00:00
|
|
|
user_groups = pool.get('res.users').read(cr, uid, [uid], ['groups_id'])[0]['groups_id']
|
|
|
|
if not transition['group_id'] in user_groups:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return _eval_expr(cr, ident, workitem, transition['condition'])
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|