From 6a3a2709efe78b2440480acb33d02e5e9f025b55 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Wed, 23 Oct 2013 15:07:05 +0200 Subject: [PATCH] [REF] Remove the useless wkf_expr.py file and copy it into workitem.py bzr revid: stw@openerp.com-20131023130705-k4u7ssba820b7hwi --- openerp/workflow/instance.py | 4 +- openerp/workflow/wkf_expr.py | 111 -------------------------------- openerp/workflow/workitem.py | 119 ++++++++++++++++++++++++++++++----- 3 files changed, 105 insertions(+), 129 deletions(-) delete mode 100644 openerp/workflow/wkf_expr.py diff --git a/openerp/workflow/instance.py b/openerp/workflow/instance.py index 4db807daaac..3d7b8cbb04e 100644 --- a/openerp/workflow/instance.py +++ b/openerp/workflow/instance.py @@ -19,8 +19,8 @@ # ############################################################################## import workitem -from helpers import Session -from helpers import Record +from openerp.workflow.helpers import Session +from openerp.workflow.helpers import Record def create(session, record, workflow_id): assert isinstance(session, Session) diff --git a/openerp/workflow/wkf_expr.py b/openerp/workflow/wkf_expr.py deleted file mode 100644 index 2c5afb0db48..00000000000 --- a/openerp/workflow/wkf_expr.py +++ /dev/null @@ -1,111 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# 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. -# -# 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 -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -""" -Evaluate workflow code found in activity actions and transition conditions. -""" - -import openerp -from openerp.tools.safe_eval import safe_eval as eval - -class Env(dict): - """ - Dictionary class used as an environment to evaluate workflow code (such as - the condition on transitions). - - This environment provides sybmols for cr, uid, id, model name, model - instance, column names, and all the record (the one obtained by browsing - the provided ID) attributes. - """ - def __init__(self, cr, uid, model, id): - self.cr = cr - self.uid = uid - self.model = model - self.id = id - self.ids = [id] - self.obj = openerp.registry(cr.dbname)[model] - self.columns = self.obj._columns.keys() + self.obj._inherit_fields.keys() - - def __getitem__(self, key): - if (key in self.columns) or (key in dir(self.obj)): - res = self.obj.browse(self.cr, self.uid, self.id) - return res[key] - else: - return super(Env, self).__getitem__(key) - -def _eval_expr(session, record, workitem, lines): - """ - Evaluate each line of ``lines`` with the ``Env`` environment, returning - the value of the last line. - """ - assert lines, 'You used a NULL action in a workflow, use dummy node instead.' - result = False - for line in lines.split('\n'): - line = line.strip() - if not line: - continue - if line == 'True': - result = True - elif line == 'False': - result = False - else: - env = Env(session.cr, session.uid, record.model, record.id) - result = eval(line, env, nocopy=True) - return result - -def execute_action(session, record, workitem, activity): - """ - Evaluate the ir.actions.server action specified in the activity. - """ - ir_actions_server = openerp.registry(session.cr.dbname)['ir.actions.server'] - context = { 'active_model': record.model, 'active_id': record.id, 'active_ids': [record.id] } - result = ir_actions_server.run(session.cr, session.uid, [activity['action_id']], context) - return result - -def execute(session, record, workitem, activity): - """ - Evaluate the action specified in the activity. - """ - return _eval_expr(session, record, workitem, activity['action']) - -def check(session, record, workitem, transition, signal): - """ - Test if a transition can be taken. The transition can be taken if: - - - the signal name matches, - - the uid is SUPERUSER_ID or the user groups contains the transition's - group, - - the condition evaluates to a truish value. - """ - if transition['signal'] and signal != transition['signal']: - return False - - if session.uid != openerp.SUPERUSER_ID and transition['group_id']: - registry = openerp.registry(session.cr.dbname) - user_groups = registry['res.users'].read(session.cr, session.uid, [session.uid], ['groups_id'])[0]['groups_id'] - if transition['group_id'] not in user_groups: - return False - - return _eval_expr(session, record, workitem, transition['condition']) - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/openerp/workflow/workitem.py b/openerp/workflow/workitem.py index 6ee99fd787d..5c2fc580cd0 100644 --- a/openerp/workflow/workitem.py +++ b/openerp/workflow/workitem.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). +# Copyright (C) 2004-2009 OpenERP S.A. (%s', (workitem['inst_id'], workitem['id'])) if activity['action']: - wkf_expr.execute(session, record, workitem, activity) + wkf_expr_execute(session, record, workitem, activity) _state_set(session, record, workitem, activity, 'complete') + elif activity['kind']=='subflow': if workitem['state']=='active': _state_set(session, record, workitem, activity, 'running') if activity.get('action', False): - id_new = wkf_expr.execute(session, record, workitem, activity) + id_new = wkf_expr_execute(session, record, workitem, activity) if not id_new: cr.execute('delete from wkf_workitem where id=%s', (workitem['id'],)) return False @@ -172,7 +259,7 @@ def _split_test(session, record, workitem, split_mode, signal, stack): alltrans = cr.dictfetchall() if split_mode=='XOR' or split_mode=='OR': for transition in alltrans: - if wkf_expr.check(session, record, workitem, transition,signal): + if wkf_expr_check(session, record, workitem, transition,signal): test = True transitions.append((transition['id'], workitem['inst_id'])) if split_mode=='XOR': @@ -180,7 +267,7 @@ def _split_test(session, record, workitem, split_mode, signal, stack): else: test = True for transition in alltrans: - if not wkf_expr.check(session, record, workitem, transition,signal): + if not wkf_expr_check(session, record, workitem, transition,signal): test = False break cr.execute('select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s', (transition['id'], workitem['inst_id']))