1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2014 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 from openerp.workflow.service import WorkflowService
24 # The new API is in openerp.workflow.workflow_service
25 # OLD API of the Workflow
27 def clear_cache(cr, uid):
28 WorkflowService.clear_cache(cr.dbname)
30 def trg_write(uid, res_type, res_id, cr):
32 Reevaluates the specified workflow instance. Thus if any condition for
33 a transition have been changed in the backend, then running ``trg_write``
34 will move the workflow over that transition.
36 :param res_type: the model name
37 :param res_id: the model instance id the workflow belongs to
38 :param cr: a database cursor
40 return WorkflowService.new(cr, uid, res_type, res_id).write()
42 def trg_trigger(uid, res_type, res_id, cr):
46 If a workflow instance is waiting for a trigger from another model, then this
47 trigger can be activated if its conditions are met.
49 :param res_type: the model name
50 :param res_id: the model instance id the workflow belongs to
51 :param cr: a database cursor
53 return WorkflowService.new(cr, uid, res_type, res_id).trigger()
55 def trg_delete(uid, res_type, res_id, cr):
57 Delete a workflow instance
59 :param res_type: the model name
60 :param res_id: the model instance id the workflow belongs to
61 :param cr: a database cursor
63 return WorkflowService.new(cr, uid, res_type, res_id).delete()
65 def trg_create(uid, res_type, res_id, cr):
67 Create a new workflow instance
69 :param res_type: the model name
70 :param res_id: the model instance id to own the created worfklow instance
71 :param cr: a database cursor
73 return WorkflowService.new(cr, uid, res_type, res_id).create()
75 def trg_validate(uid, res_type, res_id, signal, cr):
77 Fire a signal on a given workflow instance
79 :param res_type: the model name
80 :param res_id: the model instance id the workflow belongs to
81 :signal: the signal name to be fired
82 :param cr: a database cursor
84 assert isinstance(signal, basestring)
85 return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
87 def trg_redirect(uid, res_type, res_id, new_rid, cr):
89 Re-bind a workflow instance to another instance of the same model.
91 Make all workitems which are waiting for a (subflow) workflow instance
92 for the old resource point to the (first active) workflow instance for
95 :param res_type: the model name
96 :param res_id: the model instance id the workflow belongs to
97 :param new_rid: the model instance id to own the worfklow instance
98 :param cr: a database cursor
100 assert isinstance(new_rid, (long, int))
101 return WorkflowService.new(cr, uid, res_type, res_id).redirect(new_rid)
103 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: