Odoo workflowIn simple words workflow is "Perform some action in a organized way". To organize tasks or activities we use workflow. In the term of Computer Science workflow is same as the directed graph, where the nodes are called activities and arcs are called transitions. Here activities are some action that could be done on odoo server such as changing the state of some records based on some condition. We can say that the behaviour of the workflow depends on user action (for example clicking on a button).
Follwong screen shot shows that what we are going to do that.
In above image we have four states and each single state represent a group of user. The purpose of creating or using these states is to force the users to perform some action in an organized way. For example before going to the ORIC state we need to perform some checks. The another benefit of using workflows is to display related records to the right user. Now its time to jump into the code.
_name = 'workflow.example'
('External Evaluator','External Evaluator')],'State')
In above code we have created a model named "workflow_example" and in that model we have created one selection field named "state". This field contains four key value pairs (pgrc,oric,vc and external evaluator). The value of above fields will be shown as the label of workflow.
<page string="External Evaluation">
<button name="btn_submit_to_oric" string="Submit" type="object" class="oe_highlight" groups="pgrc_user"/>
<field name="external_evaluation_sub_state" widget="statusbar" statusbar_visible="PGRC,ORIC,VC,External Evaluator" readonly="1" />
In above code we have created a <page> inside our form view. In this page we have one button (to change the state after performing some action) and one field (e.g. state). In this field we used widget (widget="statusbar") attribute to show state field values as a statusbar.
Now that we have created our workflow with states and a button. Now its time to handle button event, On button click we want to perform some action and after performing right action we want to move to the next state. Below code shows how to change or move to the next state on button click.
# perform some action
# force to perform necessary action