2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2013-10-23 12:53:43 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2014-01-09 09:50:17 +00:00
|
|
|
# Copyright (C) 2004-2014 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 07:24:04 +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
|
2013-10-23 12:53:43 +00:00
|
|
|
# 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
|
|
|
##############################################################################
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2013-10-23 12:53:43 +00:00
|
|
|
from openerp.workflow.service import WorkflowService
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2013-10-23 12:53:43 +00:00
|
|
|
# The new API is in openerp.workflow.workflow_service
|
|
|
|
# OLD API of the Workflow
|
2011-06-23 09:03:57 +00:00
|
|
|
|
2013-01-30 17:37:59 +00:00
|
|
|
def clear_cache(cr, uid):
|
2013-10-23 12:53:43 +00:00
|
|
|
WorkflowService.clear_cache(cr.dbname)
|
2008-07-23 15:01:27 +00:00
|
|
|
|
2013-01-30 17:37:59 +00:00
|
|
|
def trg_write(uid, res_type, res_id, cr):
|
|
|
|
"""
|
|
|
|
Reevaluates the specified workflow instance. Thus if any condition for
|
|
|
|
a transition have been changed in the backend, then running ``trg_write``
|
|
|
|
will move the workflow over that transition.
|
|
|
|
|
|
|
|
:param res_type: the model name
|
|
|
|
:param res_id: the model instance id the workflow belongs to
|
|
|
|
:param cr: a database cursor
|
|
|
|
"""
|
2013-10-23 12:53:43 +00:00
|
|
|
return WorkflowService.new(cr, uid, res_type, res_id).write()
|
2013-01-30 17:37:59 +00:00
|
|
|
|
|
|
|
def trg_trigger(uid, res_type, res_id, cr):
|
|
|
|
"""
|
|
|
|
Activate a trigger.
|
|
|
|
|
|
|
|
If a workflow instance is waiting for a trigger from another model, then this
|
|
|
|
trigger can be activated if its conditions are met.
|
|
|
|
|
|
|
|
:param res_type: the model name
|
|
|
|
:param res_id: the model instance id the workflow belongs to
|
|
|
|
:param cr: a database cursor
|
|
|
|
"""
|
2013-10-23 12:53:43 +00:00
|
|
|
return WorkflowService.new(cr, uid, res_type, res_id).trigger()
|
2013-01-30 17:37:59 +00:00
|
|
|
|
|
|
|
def trg_delete(uid, res_type, res_id, cr):
|
|
|
|
"""
|
|
|
|
Delete a workflow instance
|
|
|
|
|
|
|
|
:param res_type: the model name
|
|
|
|
:param res_id: the model instance id the workflow belongs to
|
|
|
|
:param cr: a database cursor
|
|
|
|
"""
|
2013-10-23 12:53:43 +00:00
|
|
|
return WorkflowService.new(cr, uid, res_type, res_id).delete()
|
2013-01-30 17:37:59 +00:00
|
|
|
|
|
|
|
def trg_create(uid, res_type, res_id, cr):
|
|
|
|
"""
|
|
|
|
Create a new workflow instance
|
2008-07-23 15:01:27 +00:00
|
|
|
|
2013-01-30 17:37:59 +00:00
|
|
|
:param res_type: the model name
|
|
|
|
:param res_id: the model instance id to own the created worfklow instance
|
|
|
|
:param cr: a database cursor
|
|
|
|
"""
|
2013-10-23 12:53:43 +00:00
|
|
|
return WorkflowService.new(cr, uid, res_type, res_id).create()
|
2013-01-30 17:37:59 +00:00
|
|
|
|
|
|
|
def trg_validate(uid, res_type, res_id, signal, cr):
|
|
|
|
"""
|
|
|
|
Fire a signal on a given workflow instance
|
|
|
|
|
|
|
|
:param res_type: the model name
|
|
|
|
:param res_id: the model instance id the workflow belongs to
|
|
|
|
:signal: the signal name to be fired
|
|
|
|
:param cr: a database cursor
|
|
|
|
"""
|
2013-10-23 12:53:43 +00:00
|
|
|
assert isinstance(signal, basestring)
|
|
|
|
return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
|
2013-01-30 17:37:59 +00:00
|
|
|
|
|
|
|
def trg_redirect(uid, res_type, res_id, new_rid, cr):
|
|
|
|
"""
|
|
|
|
Re-bind a workflow instance to another instance of the same model.
|
|
|
|
|
|
|
|
Make all workitems which are waiting for a (subflow) workflow instance
|
|
|
|
for the old resource point to the (first active) workflow instance for
|
|
|
|
the new resource.
|
|
|
|
|
|
|
|
:param res_type: the model name
|
|
|
|
:param res_id: the model instance id the workflow belongs to
|
|
|
|
:param new_rid: the model instance id to own the worfklow instance
|
|
|
|
:param cr: a database cursor
|
|
|
|
"""
|
2013-10-23 12:53:43 +00:00
|
|
|
assert isinstance(new_rid, (long, int))
|
|
|
|
return WorkflowService.new(cr, uid, res_type, res_id).redirect(new_rid)
|
2013-01-30 17:37:59 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|