2
.. i18n: =========================
3
.. i18n: Workflow-Business Process
4
.. i18n: =========================
6
=========================
7
Workflow-Business Process
8
=========================
16
.. i18n: The workflow system in Open ERP is a very powerful mechanism that can describe the evolution of documents (model) in time.
18
The workflow system in Open ERP is a very powerful mechanism that can describe the evolution of documents (model) in time.
20
.. i18n: Workflows are entirely customizable, they can be adapted to the flows and trade logic of almost any company. The workflow system makes Tiny ERP very flexible and allows it to easily support changing needs without having to program new functionalities.
22
Workflows are entirely customizable, they can be adapted to the flows and trade logic of almost any company. The workflow system makes Tiny ERP very flexible and allows it to easily support changing needs without having to program new functionalities.
28
.. i18n: * description of document evolution in time
29
.. i18n: * automatic trigger of actions if some conditions are met
30
.. i18n: * management of company roles and validation steps
31
.. i18n: * management of interactions between the different objects/modules
32
.. i18n: * graphical tool for visualization of document flows
34
* description of document evolution in time
35
* automatic trigger of actions if some conditions are met
36
* management of company roles and validation steps
37
* management of interactions between the different objects/modules
38
* graphical tool for visualization of document flows
40
.. i18n: **To understand its utility, see these three examples:**
42
**To understand its utility, see these three examples:**
44
.. i18n: WkfExample1: Discount On Orders
45
.. i18n: -------------------------------
47
WkfExample1: Discount On Orders
48
-------------------------------
50
.. i18n: The first diagram represent a very basic workflow of an order:
52
The first diagram represent a very basic workflow of an order:
54
.. i18n: .. image:: images/Workflow_bc1.png
56
.. image:: images/Workflow_bc1.png
58
.. i18n: The order starts in the 'draft' state, when it is in redaction and not approved. When the user press on the 'Confirm' button, the invoice is created and the order comes into the 'CONFIRMED' state.
60
The order starts in the 'draft' state, when it is in redaction and not approved. When the user press on the 'Confirm' button, the invoice is created and the order comes into the 'CONFIRMED' state.
62
.. i18n: Then, two operations are possible:
64
Then, two operations are possible:
66
.. i18n: #. the order is done (shipped)
68
.. i18n: #. the order is canceled
70
#. the order is done (shipped)
72
#. the order is canceled
74
.. i18n: Let's suppose a company has a need not implemented in OpenERP. For example, suppose their sales staff can only offer discounts of 15% or less. Every order having a discount above 15% must be approved by the sales manager.
76
Let's suppose a company has a need not implemented in OpenERP. For example, suppose their sales staff can only offer discounts of 15% or less. Every order having a discount above 15% must be approved by the sales manager.
78
.. i18n: This modification in the sale logic doesn't need any line of python code! A simple modification of the workflow allows us to take this new need into account and add the extra validation step.
80
This modification in the sale logic doesn't need any line of python code! A simple modification of the workflow allows us to take this new need into account and add the extra validation step.
82
.. i18n: .. image:: images/Workflow_bc2.png
84
.. image:: images/Workflow_bc2.png
86
.. i18n: The workflow is thus modified as above and the orders will react as we want to. We then only need to modify the order form view and add a validation button at the desired location.
88
The workflow is thus modified as above and the orders will react as we want to. We then only need to modify the order form view and add a validation button at the desired location.
90
.. i18n: We could then further improve this workflow by sending a request to the sales manager when an order enters the 'Validation' state. Workflow nodes can execute object methods; only two lines of Python are needed to send a request asking the sales manager to validate or not the order.
92
We could then further improve this workflow by sending a request to the sales manager when an order enters the 'Validation' state. Workflow nodes can execute object methods; only two lines of Python are needed to send a request asking the sales manager to validate or not the order.
94
.. i18n: WkfExample2: A sale order that generates an invoice and a shipping order.
95
.. i18n: -------------------------------------------------------------------------
97
WkfExample2: A sale order that generates an invoice and a shipping order.
98
-------------------------------------------------------------------------
100
.. i18n: .. image:: images/Workflow_sale.png
102
.. image:: images/Workflow_sale.png
104
.. i18n: WkfExample3: Acount invoice basic workflow
106
WkfExample3: Acount invoice basic workflow
108
.. i18n: .. image:: images/Acount_inv_wkf.jpg
110
.. image:: images/Acount_inv_wkf.jpg
112
.. i18n: Defining Workflow
113
.. i18n: =================
114
.. i18n: Workflows are defined in the file server/bin/addons/base/ir/workflow/workflow.py. The first three classes defined in this file are workflow, wkf_activity and wkf_transition. They correspond to the three types of resources that are necessary to describe a workflow :
118
Workflows are defined in the file server/bin/addons/base/ir/workflow/workflow.py. The first three classes defined in this file are workflow, wkf_activity and wkf_transition. They correspond to the three types of resources that are necessary to describe a workflow :
120
.. i18n: * `workflow <http://openobject.com/wiki/index.php/WkfDefXML>`_ : the workflow,
121
.. i18n: * `wkf_activity <http://openobject.com/wiki/index.php/WorkflowActivity>`_ : the activities (nodes),
122
.. i18n: * `wkf_transition <http://openobject.com/wiki/index.php/WorkflowTransition>`_ : the transitions between the activities.
124
* `workflow <http://openobject.com/wiki/index.php/WkfDefXML>`_ : the workflow,
125
* `wkf_activity <http://openobject.com/wiki/index.php/WorkflowActivity>`_ : the activities (nodes),
126
* `wkf_transition <http://openobject.com/wiki/index.php/WorkflowTransition>`_ : the transitions between the activities.
128
.. i18n: General structure of a workflow XML file
129
.. i18n: ========================================
131
General structure of a workflow XML file
132
========================================
134
.. i18n: The general structure of a workflow XML file is as follows :
136
The general structure of a workflow XML file is as follows :
138
.. i18n: .. code-block:: xml
140
.. i18n: <?xml version="1.0"?>
143
.. i18n: <record model="workflow" id=workflow_id>
145
.. i18n: <field name="name">workflow.name</field>
146
.. i18n: <field name="osv">resource.model</field>
147
.. i18n: <field name="on_create">True | False</field>
156
<?xml version="1.0"?>
159
<record model="workflow" id=workflow_id>
161
<field name="name">workflow.name</field>
162
<field name="osv">resource.model</field>
163
<field name="on_create">True | False</field>
174
.. i18n: * **id** (here "workflow_id") is a workflow identifier. Each workflow must have an unique identifier.
175
.. i18n: * **name** (here "workflow.name") is the name of the workflow. The name of the workflow must respect the Open ERP syntax of "dotted names".
176
.. i18n: * **osv** (here "resource.model") is the name of the Tiny object we use as a model [-(Remember a Open object inherits from osv.osv, hence the '<field name="osv">')-].
177
.. i18n: * **on_create** is True if workflow.name must be instantiated automatically when resource.model is created, and False otherwise.
179
* **id** (here "workflow_id") is a workflow identifier. Each workflow must have an unique identifier.
180
* **name** (here "workflow.name") is the name of the workflow. The name of the workflow must respect the Open ERP syntax of "dotted names".
181
* **osv** (here "resource.model") is the name of the Tiny object we use as a model [-(Remember a Open object inherits from osv.osv, hence the '<field name="osv">')-].
182
* **on_create** is True if workflow.name must be instantiated automatically when resource.model is created, and False otherwise.
188
.. i18n: The workflow **"sale.order.basic"** defined in addons/sale/sale_workflow.xml follows exactly this model, the code of its workflow tag is :
190
The workflow **"sale.order.basic"** defined in addons/sale/sale_workflow.xml follows exactly this model, the code of its workflow tag is :
192
.. i18n: .. code-block:: xml
194
.. i18n: <record model="workflow" id="wkf_sale">
196
.. i18n: <field name="name">sale.order.basic</field>
197
.. i18n: <field name="osv">sale.order</field>
198
.. i18n: <field name="on_create">True</field>
204
<record model="workflow" id="wkf_sale">
206
<field name="name">sale.order.basic</field>
207
<field name="osv">sale.order</field>
208
<field name="on_create">True</field>
218
.. i18n: Introduction
219
.. i18n: ------------
224
.. i18n: The wkf_activity class represents the nodes of workflows. These nodes are the actions to be executed.
226
The wkf_activity class represents the nodes of workflows. These nodes are the actions to be executed.
240
.. i18n: .. image:: images/Wkf_split.png
242
.. image:: images/Wkf_split.png
244
.. i18n: * XOR: One necessary transition, takes the first one found (default).
245
.. i18n: * OR : Take only valid transitions (0 or more) in sequential order.
246
.. i18n: * AND: All valid transitions are launched at the same time (fork).
248
* XOR: One necessary transition, takes the first one found (default).
249
* OR : Take only valid transitions (0 or more) in sequential order.
250
* AND: All valid transitions are launched at the same time (fork).
252
.. i18n: In the OR and AND separation mode, certain workitems can be generated.
254
In the OR and AND separation mode, certain workitems can be generated.
256
.. i18n: In the AND mode, the activity waits for all transitions to be valid, even if some of them are already valid. They are all triggered at the same time.
260
In the AND mode, the activity waits for all transitions to be valid, even if some of them are already valid. They are all triggered at the same time.
264
.. i18n: .. image:: images/Wkf_join.png
266
.. image:: images/Wkf_join.png
268
.. i18n: * **XOR**: One transition necessary to continue to the destination activity (default).
269
.. i18n: * **AND**: Waits for all transition conditions to be valid to execute the destination activity.
271
* **XOR**: One transition necessary to continue to the destination activity (default).
272
* **AND**: Waits for all transition conditions to be valid to execute the destination activity.
280
.. i18n: :The type of the activity can take several values:
282
:The type of the activity can take several values:
284
.. i18n: * **DUMMY**: Do nothing (default).
285
.. i18n: * **FUNCTION**: Execute the function selected by an action.
286
.. i18n: * **SUBFLOW**: Execute a sub-workflow SUBFLOW_ID. The action method must return the ID of the concerned resource by the subflow ! If the action returns False, the workitem disappears !
287
.. i18n: * **STOPALL**:
289
* **DUMMY**: Do nothing (default).
290
* **FUNCTION**: Execute the function selected by an action.
291
* **SUBFLOW**: Execute a sub-workflow SUBFLOW_ID. The action method must return the ID of the concerned resource by the subflow ! If the action returns False, the workitem disappears !
294
.. i18n: A sub-workflow is executed when an activity is of the type SUBFLOW. This activity ends when the sub-workflow has finished. While the sub-workflow is active, the workitem of this activity is frozen.
296
A sub-workflow is executed when an activity is of the type SUBFLOW. This activity ends when the sub-workflow has finished. While the sub-workflow is active, the workitem of this activity is frozen.
304
.. i18n: The action indicates the method to execute when a workitem comes into this activity. The method must be defined in a object which belongs this workflow and have the following signature:
306
The action indicates the method to execute when a workitem comes into this activity. The method must be defined in a object which belongs this workflow and have the following signature:
308
.. i18n: def object_method(self, cr, uid, ids):
310
def object_method(self, cr, uid, ids):
312
.. i18n: In the action though, they will be called by a statement like:
314
In the action though, they will be called by a statement like:
316
.. i18n: object_method()
336
.. i18n: Indicates if the node is a start node. When a new instance of a workflow is created, a workitem is activated for each activity marked as a flow_start.
338
Indicates if the node is a start node. When a new instance of a workflow is created, a workitem is activated for each activity marked as a flow_start.
340
.. i18n: Be warned to not use this flag unless your activity really is a "flow start". There are tiny versions that do not care about the tags contents like "true" or "false". Using such tag and tiny version, you will always end up whith an activity which is tagged as "flow start = true", leaving u with a nasty hunt to find out where your workflowdesign could be wrong.
342
Be warned to not use this flag unless your activity really is a "flow start". There are tiny versions that do not care about the tags contents like "true" or "false". Using such tag and tiny version, you will always end up whith an activity which is tagged as "flow start = true", leaving u with a nasty hunt to find out where your workflowdesign could be wrong.
350
.. i18n: Indicates if the node is an ending node. When all the active workitems for a given instance come in the node marked by flow_stop, the workflow is finished.
352
Indicates if the node is an ending node. When all the active workitems for a given instance come in the node marked by flow_stop, the workflow is finished.
354
.. i18n: Be warned to not use this flag unless your activity really is a "flow stop". There are tiny versions that do not care about the tags contents like "true" or "false". Using such tag and tiny version, you will always end up whith an activity which is tagged as "flow stop = true", leaving u with a nasty hunt to find out where your workflowdesign could be wrong.
356
Be warned to not use this flag unless your activity really is a "flow stop". There are tiny versions that do not care about the tags contents like "true" or "false". Using such tag and tiny version, you will always end up whith an activity which is tagged as "flow stop = true", leaving u with a nasty hunt to find out where your workflowdesign could be wrong.
364
.. i18n: The workflow which this activity belongs to.
365
.. i18n: Defining activities using XML files
367
The workflow which this activity belongs to.
368
Defining activities using XML files
370
.. i18n: The general structure of an activity record is as follows
371
.. i18n: ---------------------------------------------------------
373
The general structure of an activity record is as follows
374
---------------------------------------------------------
376
.. i18n: .. code-block:: xml
378
.. i18n: <record model="workflow.activity" id="''activity_id''">
379
.. i18n: <field name="wkf_id" ref="''workflow_id''"/>
380
.. i18n: <field name="name">''activity.name''</field>::
382
.. i18n: <field name="split_mode">XOR | OR | AND</field>
383
.. i18n: <field name="join_mode">XOR | AND</field>
384
.. i18n: <field name="kind">dummy | function | subflow | stopall</field>
386
.. i18n: <field name="action">''(...)''</field>
387
.. i18n: <field name="signal_send">''(...)''</field>
388
.. i18n: <field name="flow_start">True | False</field>
389
.. i18n: <field name="flow_stop">True | False</field>
394
<record model="workflow.activity" id="''activity_id''">
395
<field name="wkf_id" ref="''workflow_id''"/>
396
<field name="name">''activity.name''</field>::
398
<field name="split_mode">XOR | OR | AND</field>
399
<field name="join_mode">XOR | AND</field>
400
<field name="kind">dummy | function | subflow | stopall</field>
402
<field name="action">''(...)''</field>
403
<field name="signal_send">''(...)''</field>
404
<field name="flow_start">True | False</field>
405
<field name="flow_stop">True | False</field>
408
.. i18n: The first two arguments **wkf_id** and name are mandatory. Be warned to not use **flow_start** and **flow_stop** unless your activity really is a **flow start** or **flow_stop**. There are tiny versions that do not care about the tags contents like "True" or "False".
410
The first two arguments **wkf_id** and name are mandatory. Be warned to not use **flow_start** and **flow_stop** unless your activity really is a **flow start** or **flow_stop**. There are tiny versions that do not care about the tags contents like "True" or "False".
416
.. i18n: There are too many possibilities of activity definition to choose from using this definition. We recommend you to have a look at the file **server/bin/addons/sale/sale_workflow.xml** for several examples of activity definitions.
418
There are too many possibilities of activity definition to choose from using this definition. We recommend you to have a look at the file **server/bin/addons/sale/sale_workflow.xml** for several examples of activity definitions.
426
.. i18n: Introduction
427
.. i18n: ------------
432
.. i18n: Workflow transitions are the conditions to be satisfied to go from one activity to the next one. They are represented by one-way arrows joining two activities.
434
Workflow transitions are the conditions to be satisfied to go from one activity to the next one. They are represented by one-way arrows joining two activities.
436
.. i18n: The conditions are of different types:
438
The conditions are of different types:
440
.. i18n: * role to satisfy by the user
441
.. i18n: * button pressed in the interface
442
.. i18n: * end of a subflow through a selected activity of subflow
444
* role to satisfy by the user
445
* button pressed in the interface
446
* end of a subflow through a selected activity of subflow
448
.. i18n: The roles and signals are evaluated before the expression. If a role or a signal is false, the expression will not be evaluated.
450
The roles and signals are evaluated before the expression. If a role or a signal is false, the expression will not be evaluated.
452
.. i18n: Transition tests may not write values in objects.
458
Transition tests may not write values in objects.
464
.. i18n: Source activity. When this activity is over, the condition is tested to determine if we can start the ACT_TO activity.
466
Source activity. When this activity is over, the condition is tested to determine if we can start the ACT_TO activity.
476
.. i18n: The destination activity.
478
The destination activity.
488
.. i18n: **Expression** to be satisfied if we want the transition done.
490
**Expression** to be satisfied if we want the transition done.
500
.. i18n: When the operation of transition comes from a button pressed in the client form, signal tests the name of the pressed button.
502
When the operation of transition comes from a button pressed in the client form, signal tests the name of the pressed button.
504
.. i18n: If signal is NULL, no button is necessary to validate this transition.
506
If signal is NULL, no button is necessary to validate this transition.
516
.. i18n: The **role** that a user must have to validate this transition.
517
.. i18n: Defining Transitions Using XML Files
519
The **role** that a user must have to validate this transition.
520
Defining Transitions Using XML Files
522
.. i18n: The general structure of a transition record is as follows
524
The general structure of a transition record is as follows
526
.. i18n: .. code-block:: xml
528
.. i18n: <record model="workflow.transition" id="transition_id">
530
.. i18n: <field name="act_from" ref="activity_id'_1_'"/>
531
.. i18n: <field name="act_to" ref="activity_id'_2_'"/>
533
.. i18n: <field name="signal">(...)</field>
534
.. i18n: <field name="role_id" ref="role_id'_1_'"/>
535
.. i18n: <field name="condition">(...)</field>
537
.. i18n: <field name="trigger_model">(...)</field>
538
.. i18n: <field name="trigger_expr_id">(...)</field>
544
<record model="workflow.transition" id="transition_id">
546
<field name="act_from" ref="activity_id'_1_'"/>
547
<field name="act_to" ref="activity_id'_2_'"/>
549
<field name="signal">(...)</field>
550
<field name="role_id" ref="role_id'_1_'"/>
551
<field name="condition">(...)</field>
553
<field name="trigger_model">(...)</field>
554
<field name="trigger_expr_id">(...)</field>
558
.. i18n: Only the fields **act_from** and **act_to** are mandatory.
560
Only the fields **act_from** and **act_to** are mandatory.
568
.. i18n: Expressions are written as in python:
570
Expressions are written as in python:
574
.. i18n: * 'hello' in ['hello','bye']
578
* 'hello' in ['hello','bye']
580
.. i18n: Any field from the resource the workflow refers to can be used in these expressions. For example, if you were creating a workflow for partner addresses, you could use expressions like:
582
Any field from the resource the workflow refers to can be used in these expressions. For example, if you were creating a workflow for partner addresses, you could use expressions like:
585
.. i18n: * phone==mobile
592
.. i18n: Roles can be attached to transitions. If a role is given for a transition, that transition can only be executed if the user who triggered it possess the necessary role.
596
Roles can be attached to transitions. If a role is given for a transition, that transition can only be executed if the user who triggered it possess the necessary role.
598
.. i18n: Each user can have one or several roles. Roles are defined in a tree of roles, parent roles having the rights of all their children.
600
Each user can have one or several roles. Roles are defined in a tree of roles, parent roles having the rights of all their children.
610
.. i18n: * Technical manager
612
.. i18n: - Lead developper
618
.. i18n: + Developpers
624
.. i18n: * Sales manager
626
.. i18n: - Commercials
634
.. i18n: Let's suppose we handle our own bug database and that the action of marking a bug as valid needs the Testers role. In the example tree above, marking a bug as valid could be done by all the users having the following roles: Testers, Lead developper, Technical manager, CEO.
636
Let's suppose we handle our own bug database and that the action of marking a bug as valid needs the Testers role. In the example tree above, marking a bug as valid could be done by all the users having the following roles: Testers, Lead developper, Technical manager, CEO.
638
.. i18n: Error handling
639
.. i18n: ==============
644
.. i18n: As of this writing, there is no exception handling in workflows.
646
As of this writing, there is no exception handling in workflows.
648
.. i18n: Workflows being made of several actions executed in batch, they can't trigger exceptions. In order to improve the execution efficiency and to release a maximum of locks, workflows commit at the end of each activity. This approach is reasonable because an activity is only started if the conditions of the transactions are satisfied.
650
Workflows being made of several actions executed in batch, they can't trigger exceptions. In order to improve the execution efficiency and to release a maximum of locks, workflows commit at the end of each activity. This approach is reasonable because an activity is only started if the conditions of the transactions are satisfied.
652
.. i18n: The only problem comes from exceptions due to programming errors; in that case, only transactions belonging to the entirely terminated activities are executed. Other transactions are "rolled back".
654
The only problem comes from exceptions due to programming errors; in that case, only transactions belonging to the entirely terminated activities are executed. Other transactions are "rolled back".
656
.. i18n: Creating a Workflow
657
.. i18n: ===================
662
.. i18n: Steps for creating a simple state-changing workflow for a custom module called **mymod**
664
Steps for creating a simple state-changing workflow for a custom module called **mymod**
666
.. i18n: Define the States of your object
667
.. i18n: --------------------------------
669
Define the States of your object
670
--------------------------------
672
.. i18n: The first step is to define the States your object can be in. We do this by adding a 'state' field to our object, in the _columns collection
674
The first step is to define the States your object can be in. We do this by adding a 'state' field to our object, in the _columns collection
676
.. i18n: .. code-block:: python
678
.. i18n: _columns = {
680
.. i18n: 'state': fields.selection([
681
.. i18n: ('new','New'),
682
.. i18n: ('assigned','Assigned'),
683
.. i18n: ('negotiation','Negotiation'),
684
.. i18n: ('won','Won'),
685
.. i18n: ('lost','Lost')], 'Stage', readonly=True),
688
.. code-block:: python
692
'state': fields.selection([
694
('assigned','Assigned'),
695
('negotiation','Negotiation'),
697
('lost','Lost')], 'Stage', readonly=True),
700
.. i18n: Define the State-change Handling Methods
701
.. i18n: ----------------------------------------
703
Define the State-change Handling Methods
704
----------------------------------------
706
.. i18n: Add the following additional methods to your object. These will be called by our workflow buttons
708
Add the following additional methods to your object. These will be called by our workflow buttons
710
.. i18n: .. code-block:: python
712
.. i18n: def mymod_new(self, cr, uid, ids):
713
.. i18n: self.write(cr, uid, ids, { 'state' : 'new' })
716
.. i18n: def mymod_assigned(self, cr, uid, ids):
717
.. i18n: self.write(cr, uid, ids, { 'state' : 'assigned' })
720
.. i18n: def mymod_negotiation(self, cr, uid, ids):
721
.. i18n: self.write(cr, uid, ids, { 'state' : 'negotiation' })
724
.. i18n: def mymod_won(self, cr, uid, ids):
725
.. i18n: self.write(cr, uid, ids, { 'state' : 'won' })
728
.. i18n: def mymod_lost(self, cr, uid, ids):
729
.. i18n: self.write(cr, uid, ids, { 'state' : 'lost' })
732
.. code-block:: python
734
def mymod_new(self, cr, uid, ids):
735
self.write(cr, uid, ids, { 'state' : 'new' })
738
def mymod_assigned(self, cr, uid, ids):
739
self.write(cr, uid, ids, { 'state' : 'assigned' })
742
def mymod_negotiation(self, cr, uid, ids):
743
self.write(cr, uid, ids, { 'state' : 'negotiation' })
746
def mymod_won(self, cr, uid, ids):
747
self.write(cr, uid, ids, { 'state' : 'won' })
750
def mymod_lost(self, cr, uid, ids):
751
self.write(cr, uid, ids, { 'state' : 'lost' })
754
.. i18n: Obviously you would extend these methods in the future to do something more useful!
755
.. i18n: Create your Workflow XML file
756
.. i18n: -----------------------------
758
Obviously you would extend these methods in the future to do something more useful!
759
Create your Workflow XML file
760
-----------------------------
762
.. i18n: There are three types of records we need to define in a file called mymod_workflow.xml
764
There are three types of records we need to define in a file called mymod_workflow.xml
766
.. i18n: #. Workflow header record (only one of these)
768
#. Workflow header record (only one of these)
770
.. i18n: .. code-block:: xml
772
.. i18n: <record model="workflow" id="wkf_mymod">
773
.. i18n: <field name="name">mymod.wkf</field>
774
.. i18n: <field name="osv">mymod.mymod</field>
775
.. i18n: <field name="on_create">True</field>
780
<record model="workflow" id="wkf_mymod">
781
<field name="name">mymod.wkf</field>
782
<field name="osv">mymod.mymod</field>
783
<field name="on_create">True</field>
786
.. i18n: #. Workflow Activity records
788
#. Workflow Activity records
790
.. i18n: These define the actions that should be executed when the workflow reaches a particular state
792
These define the actions that should be executed when the workflow reaches a particular state
794
.. i18n: .. code-block:: xml
796
.. i18n: <record model="workflow.activity" id="act_new">
797
.. i18n: <field name="wkf_id" ref="wkf_mymod" />
798
.. i18n: <field name="flow_start">True</field>
799
.. i18n: <field name="name">new</field>
800
.. i18n: <field name="kind">function</field>
801
.. i18n: <field name="action">mymod_new()</field>
804
.. i18n: <record model="workflow.activity" id="act_assigned">
805
.. i18n: <field name="wkf_id" ref="wkf_mymod" />
806
.. i18n: <field name="name">assigned</field>
807
.. i18n: <field name="kind">function</field>
808
.. i18n: <field name="action">mymod_assigned()</field>
811
.. i18n: <record model="workflow.activity" id="act_negotiation">
812
.. i18n: <field name="wkf_id" ref="wkf_mymod" />
813
.. i18n: <field name="name">negotiation</field>
814
.. i18n: <field name="kind">function</field>
815
.. i18n: <field name="action">mymod_negotiation()</field>
818
.. i18n: <record model="workflow.activity" id="act_won">
819
.. i18n: <field name="wkf_id" ref="wkf_mymod" />
820
.. i18n: <field name="name">won</field>
821
.. i18n: <field name="kind">function</field>
822
.. i18n: <field name="action">mymod_won()</field>
823
.. i18n: <field name="flow_stop">True</field>
826
.. i18n: <record model="workflow.activity" id="act_lost">
827
.. i18n: <field name="wkf_id" ref="wkf_mymod" />
828
.. i18n: <field name="name">lost</field>
829
.. i18n: <field name="kind">function</field>
830
.. i18n: <field name="action">mymod_lost()</field>
831
.. i18n: <field name="flow_stop">True</field>
836
<record model="workflow.activity" id="act_new">
837
<field name="wkf_id" ref="wkf_mymod" />
838
<field name="flow_start">True</field>
839
<field name="name">new</field>
840
<field name="kind">function</field>
841
<field name="action">mymod_new()</field>
844
<record model="workflow.activity" id="act_assigned">
845
<field name="wkf_id" ref="wkf_mymod" />
846
<field name="name">assigned</field>
847
<field name="kind">function</field>
848
<field name="action">mymod_assigned()</field>
851
<record model="workflow.activity" id="act_negotiation">
852
<field name="wkf_id" ref="wkf_mymod" />
853
<field name="name">negotiation</field>
854
<field name="kind">function</field>
855
<field name="action">mymod_negotiation()</field>
858
<record model="workflow.activity" id="act_won">
859
<field name="wkf_id" ref="wkf_mymod" />
860
<field name="name">won</field>
861
<field name="kind">function</field>
862
<field name="action">mymod_won()</field>
863
<field name="flow_stop">True</field>
866
<record model="workflow.activity" id="act_lost">
867
<field name="wkf_id" ref="wkf_mymod" />
868
<field name="name">lost</field>
869
<field name="kind">function</field>
870
<field name="action">mymod_lost()</field>
871
<field name="flow_stop">True</field>
874
.. i18n: #. Workflow Transition records
876
#. Workflow Transition records
878
.. i18n: These define the possible transitions between workflow states
880
These define the possible transitions between workflow states
882
.. i18n: .. code-block:: xml
884
.. i18n: <record model="workflow.transition" id="t1">
885
.. i18n: <field name="act_from" ref="act_new" />
886
.. i18n: <field name="act_to" ref="act_assigned" />
887
.. i18n: <field name="signal">mymod_assigned</field>
890
.. i18n: <record model="workflow.transition" id="t2">
891
.. i18n: <field name="act_from" ref="act_assigned" />
892
.. i18n: <field name="act_to" ref="act_negotiation" />
893
.. i18n: <field name="signal">mymod_negotiation</field>
896
.. i18n: <record model="workflow.transition" id="t3">
897
.. i18n: <field name="act_from" ref="act_negotiation" />
898
.. i18n: <field name="act_to" ref="act_won" />
899
.. i18n: <field name="signal">mymod_won</field>
902
.. i18n: <record model="workflow.transition" id="t4">
903
.. i18n: <field name="act_from" ref="act_negotiation" />
904
.. i18n: <field name="act_to" ref="act_lost" />
905
.. i18n: <field name="signal">mymod_lost</field>
910
<record model="workflow.transition" id="t1">
911
<field name="act_from" ref="act_new" />
912
<field name="act_to" ref="act_assigned" />
913
<field name="signal">mymod_assigned</field>
916
<record model="workflow.transition" id="t2">
917
<field name="act_from" ref="act_assigned" />
918
<field name="act_to" ref="act_negotiation" />
919
<field name="signal">mymod_negotiation</field>
922
<record model="workflow.transition" id="t3">
923
<field name="act_from" ref="act_negotiation" />
924
<field name="act_to" ref="act_won" />
925
<field name="signal">mymod_won</field>
928
<record model="workflow.transition" id="t4">
929
<field name="act_from" ref="act_negotiation" />
930
<field name="act_to" ref="act_lost" />
931
<field name="signal">mymod_lost</field>
934
.. i18n: Add mymod_workflow.xml to __terp__.py
936
Add mymod_workflow.xml to __terp__.py
938
.. i18n: Edit your module's __terp__.py and add mymod_workflow.xml to the "update_xml" array, so that OpenERP picks it up next time your module is loaded.
939
.. i18n: Add Workflow Buttons to your View
941
Edit your module's __terp__.py and add mymod_workflow.xml to the "update_xml" array, so that OpenERP picks it up next time your module is loaded.
942
Add Workflow Buttons to your View
944
.. i18n: The final step is to add the required buttons to mymod_views.xml file.
946
The final step is to add the required buttons to mymod_views.xml file.
948
.. i18n: Add the following at the end of the <form> section of your object's view definition:
950
Add the following at the end of the <form> section of your object's view definition:
952
.. i18n: .. code-block:: xml
954
.. i18n: <separator string="Workflow Actions" colspan="4"/>
955
.. i18n: <group colspan="4" col="3">
956
.. i18n: <button name="mymod_assigned" string="Assigned" states="new" />
957
.. i18n: <button name="mymod_negotiation" string="In Negotiation" states="assigned" />
958
.. i18n: <button name="mymod_won" string="Won" states="negotiating" />
959
.. i18n: <button name="mymod_lost" string="Lost" states="negotiating" />
964
<separator string="Workflow Actions" colspan="4"/>
965
<group colspan="4" col="3">
966
<button name="mymod_assigned" string="Assigned" states="new" />
967
<button name="mymod_negotiation" string="In Negotiation" states="assigned" />
968
<button name="mymod_won" string="Won" states="negotiating" />
969
<button name="mymod_lost" string="Lost" states="negotiating" />
974
.. i18n: Now use the Module Manager to install or update your module. If you have done everything correctly you shouldn't get any errors. You can check if your workflow is installed in Administration -> Customisation -> Workflow Definitions
978
Now use the Module Manager to install or update your module. If you have done everything correctly you shouldn't get any errors. You can check if your workflow is installed in Administration -> Customisation -> Workflow Definitions
980
.. i18n: When you are testing, remember that the workflow will only apply to NEW records that you create.
982
When you are testing, remember that the workflow will only apply to NEW records that you create.
984
.. i18n: Troubleshooting
985
.. i18n: ---------------
986
.. i18n: If your buttons do not seem to be doing anything, one of the following two things are likely:
990
If your buttons do not seem to be doing anything, one of the following two things are likely:
992
.. i18n: 1. The record you are working on does not have a Workflow Instance record associated with it (it was probably created before you defined your workflow)
993
.. i18n: 2. You have not set the "osv" field correctly in your workflow XML file
995
1. The record you are working on does not have a Workflow Instance record associated with it (it was probably created before you defined your workflow)
996
2. You have not set the "osv" field correctly in your workflow XML file