Friday, January 28, 2011

Wizards and Links in openERP

    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.



  • the next step name (determine which state will be next)



  • the button string (to display for the client)



  • the gtk stock item without the stock prefix



  • 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.

    6 comments:

    1. Great post, I was kinda lost with the wizard development. Thanks btw.

      ReplyDelete
    2. Hi Gayan,
      Sorry for the late reply.For wizard creation here i specified is by using "wizard.interface",which was mainly used in OpenERP 5.x.x,In openERP 6 and above versions "osv.osv_memory" is used,which is much more simpler than 'wizard.interface' but sometimes we use 'wizard.interface' for example if we want to create two reports at the same time. This is not possible using 'osv.osv_memory'.

      ReplyDelete
    3. hi great post, it helps me on creating my aging view using link, Iam using 5.0.3, I know this is old post but just hoping if your still there,

      can you help me how to add wizard action in the print button?
      ex: on a chart of account module, when I click print there is a report Account balance which is a wizard gets a few params and export it to PDF(using .RML) I what almost the same functionality but export it to Spreadsheet ODS file. I check the said module but I face dead end.

      hope you could help me thanks

      ReplyDelete
      Replies
      1. Hi Nick,
        You can change the report type by going through Administrator > Customization > Low Level Objects >Actions > Report. Select your report name, there you can see a field report_type. Provide the report type as PDF.

        Delete
    4. hi,
      I am a beginner in openerp and I want to implement a module that returns a PDF report containing the list of projects as date1 <start time <date2.

      date1 and date2 recover from the form

      I'm blocked for a long time

      ReplyDelete
      Replies
      1. http://zbeanztech.com/blog/creating-jasper-report-using-osvmemory-openerp-6
        you can find example module here.

        Delete