diff options
Diffstat (limited to 'openerp/workflow/__init__.py')
| -rw-r--r-- | openerp/workflow/__init__.py | 68 |
1 files changed, 15 insertions, 53 deletions
diff --git a/openerp/workflow/__init__.py b/openerp/workflow/__init__.py index f823a63fd42..efffe9705fe 100644 --- a/openerp/workflow/__init__.py +++ b/openerp/workflow/__init__.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). +# Copyright (C) 2004-2014 Tiny SPRL (<http://tiny.be>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -15,16 +15,17 @@ # 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 <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## -import instance +from openerp.workflow.service import WorkflowService -wkf_on_create_cache = {} +# The new API is in openerp.workflow.workflow_service +# OLD API of the Workflow def clear_cache(cr, uid): - wkf_on_create_cache[cr.dbname]={} + WorkflowService.clear_cache(cr.dbname) def trg_write(uid, res_type, res_id, cr): """ @@ -36,10 +37,7 @@ def trg_write(uid, res_type, res_id, cr): :param res_id: the model instance id the workflow belongs to :param cr: a database cursor """ - ident = (uid,res_type,res_id) - cr.execute('select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (res_id or None,res_type or None, 'active')) - for (id,) in cr.fetchall(): - instance.update(cr, id, ident) + return WorkflowService.new(cr, uid, res_type, res_id).write() def trg_trigger(uid, res_type, res_id, cr): """ @@ -52,12 +50,7 @@ def trg_trigger(uid, res_type, res_id, cr): :param res_id: the model instance id the workflow belongs to :param cr: a database cursor """ - cr.execute('select instance_id from wkf_triggers where res_id=%s and model=%s', (res_id,res_type)) - res = cr.fetchall() - for (instance_id,) in res: - cr.execute('select %s,res_type,res_id from wkf_instance where id=%s', (uid, instance_id,)) - ident = cr.fetchone() - instance.update(cr, instance_id, ident) + return WorkflowService.new(cr, uid, res_type, res_id).trigger() def trg_delete(uid, res_type, res_id, cr): """ @@ -67,8 +60,7 @@ def trg_delete(uid, res_type, res_id, cr): :param res_id: the model instance id the workflow belongs to :param cr: a database cursor """ - ident = (uid,res_type,res_id) - instance.delete(cr, ident) + return WorkflowService.new(cr, uid, res_type, res_id).delete() def trg_create(uid, res_type, res_id, cr): """ @@ -78,16 +70,7 @@ def trg_create(uid, res_type, res_id, cr): :param res_id: the model instance id to own the created worfklow instance :param cr: a database cursor """ - ident = (uid,res_type,res_id) - wkf_on_create_cache.setdefault(cr.dbname, {}) - if res_type in wkf_on_create_cache[cr.dbname]: - wkf_ids = wkf_on_create_cache[cr.dbname][res_type] - else: - cr.execute('select id from wkf where osv=%s and on_create=True', (res_type,)) - wkf_ids = cr.fetchall() - wkf_on_create_cache[cr.dbname][res_type] = wkf_ids - for (wkf_id,) in wkf_ids: - instance.create(cr, ident, wkf_id) + return WorkflowService.new(cr, uid, res_type, res_id).create() def trg_validate(uid, res_type, res_id, signal, cr): """ @@ -98,14 +81,8 @@ def trg_validate(uid, res_type, res_id, signal, cr): :signal: the signal name to be fired :param cr: a database cursor """ - result = False - ident = (uid,res_type,res_id) - # ids of all active workflow instances for a corresponding resource (id, model_nam) - cr.execute('select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (res_id, res_type, 'active')) - for (id,) in cr.fetchall(): - res2 = instance.validate(cr, id, ident, signal) - result = result or res2 - return result + assert isinstance(signal, basestring) + return WorkflowService.new(cr, uid, res_type, res_id).validate(signal) def trg_redirect(uid, res_type, res_id, new_rid, cr): """ @@ -120,22 +97,7 @@ def trg_redirect(uid, res_type, res_id, new_rid, cr): :param new_rid: the model instance id to own the worfklow instance :param cr: a database cursor """ - # get ids of wkf instances for the old resource (res_id) -#CHECKME: shouldn't we get only active instances? - cr.execute('select id, wkf_id from wkf_instance where res_id=%s and res_type=%s', (res_id, res_type)) - for old_inst_id, wkf_id in cr.fetchall(): - # first active instance for new resource (new_rid), using same wkf - cr.execute( - 'SELECT id '\ - 'FROM wkf_instance '\ - 'WHERE res_id=%s AND res_type=%s AND wkf_id=%s AND state=%s', - (new_rid, res_type, wkf_id, 'active')) - new_id = cr.fetchone() - if new_id: - # select all workitems which "wait" for the old instance - cr.execute('select id from wkf_workitem where subflow_id=%s', (old_inst_id,)) - for (item_id,) in cr.fetchall(): - # redirect all those workitems to the wkf instance of the new resource - cr.execute('update wkf_workitem set subflow_id=%s where id=%s', (new_id[0], item_id)) + assert isinstance(new_rid, (long, int)) + return WorkflowService.new(cr, uid, res_type, res_id).redirect(new_rid) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
