[IMP] models: add check for common conversion error in field definitions
[odoo/odoo.git] / openerp / workflow / __init__.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2014 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from openerp.workflow.service import WorkflowService
23
24 # The new API is in openerp.workflow.workflow_service
25 # OLD API of the Workflow
26
27 def clear_cache(cr, uid):
28     WorkflowService.clear_cache(cr.dbname)
29
30 def trg_write(uid, res_type, res_id, cr):
31     """
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.
35
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
39     """
40     return WorkflowService.new(cr, uid, res_type, res_id).write()
41
42 def trg_trigger(uid, res_type, res_id, cr):
43     """
44     Activate a trigger.
45
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.
48
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
52     """
53     return WorkflowService.new(cr, uid, res_type, res_id).trigger()
54
55 def trg_delete(uid, res_type, res_id, cr):
56     """
57     Delete a workflow instance
58
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
62     """
63     return WorkflowService.new(cr, uid, res_type, res_id).delete()
64
65 def trg_create(uid, res_type, res_id, cr):
66     """
67     Create a new workflow instance
68
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
72     """
73     return WorkflowService.new(cr, uid, res_type, res_id).create()
74
75 def trg_validate(uid, res_type, res_id, signal, cr):
76     """
77     Fire a signal on a given workflow instance
78
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
83     """
84     assert isinstance(signal, basestring)
85     return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
86
87 def trg_redirect(uid, res_type, res_id, new_rid, cr):
88     """
89     Re-bind a workflow instance to another instance of the same model.
90
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
93     the new resource.
94
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
99     """
100     assert isinstance(new_rid, (long, int))
101     return WorkflowService.new(cr, uid, res_type, res_id).redirect(new_rid)
102
103 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: