Wizard describe interaction sequences between the client and the server. Wizards provide a form for the client to complete it. Then client can sent the completed form back to the server and server executes some function and return another form to the user or will save the information provided by the client in the database.
To define a wizard, you have to create a class inheriting from wizard.interface and instantiate it. Each wizard must have a unique name. The wizard must define a dictionary named states which defines all its steps.
The ‘states’ dictionary define all the states of the wizard.In this example; init, test1, test2 and test3.
A wizard always starts in the init state and ends in the end state. A state defines two things: a list of actions and a result.
- List of actions: Each state of a wizard defines a list of actions which are executed when the wizard enters the state. This list can be empty.
- Result : Specifies the next state/step. The wizard will continue to the next state and if the next state given is "end" then the wizard will stop.
- The result have different types. They are form, action, choice, print etc.
- If the type is form then the client will get a form view.
- If the type is action then a user_defined_function(action) will be executed and the resulting action will be performed.
- If the type is choice then also a function will be executed. This function will return the name of the next state of the wizard.
- If the type is print then we have to provide the name of the report to be printed.
The type=form indicate that this step is a dialog to the client. We have to provide the fields and the xml view part inside our wizard.
Each step/state of a wizard can have several buttons.Those are located on the bottom right of the dialog box. The list of buttons for each step of the wizard is declared in the state key of its result dictionary.
Dynamic Forms and Fields in Wizard
Here I create a function "_get_defaults" which returns a dictionary self.states['test']['result']. Here I'm dynamically providing values to the dictionary "states". The function "_get_defaults" given below.
The function gets the limit of fields and forms from the previous wizard state using its field name mainly I'm assuming that the data to be added to the field is a character field and I had created the fields according to this assumption. Try yourself and find out its output.
The XML file
After completing the code in the wizard we have to add the wizard to the view part. We have to add the following statement to the xml file for getting the wizard in the client interface
--->id--> id is just a unique name.
--->model-->model is the place where we want to display the wizard.
--->name-->name given here is passed in the instance of the class test_wizard_college
By adding the following statement inside our student view a new button will be created inside .
If we want the wizard as a menu item then
here action is the wizard id, and parent is given as the root menu
LINKS
A link is different from wizard. A link creates a connection to a model from a model. To add a link from one model to another model we have to use act_window
Here res_model is the resulting model in which the link will take us to this model, src_model is the source model in which where the link will be shown.