Thursday, December 15, 2011

Using widgets in openerp 6.1

We have seen in OpenERP web/gtk client that some fields which are defined as many2one fields are shown as selection field or a float field which are shown in web/gtk client as a progress bar. I was confused when I first saw this. Then I came to know about widget given in XML file.
To apply widget for a field, go to the XML file, find the line where that field is specified then add widget='widget_name'
Example:
<field name="my_field" widget='widget_name'/>

In this blog I'm specifying different types of widgets that we can use in OpenERP.
  • selection :I have a many2one field to 'res.partner' and I don't want other users to get the data of 'res.partner' from that field. So I make the field as a selection by applying the widget so that only the name of the records will be shown.
    <field name="partner_id" widget='selection'/>
Progress Bar
  • progressbar : I have a float field and I want to show it as a progress bar. Then I use widget="progressbar". This field will be always a functional field which returns a float number. You can see this type of field in project.
    <field name="progress_rate" widget='progressbar'/>  

Status bar in Sale Order
  • statusbar : You may have seen in sale, purchase, invoice etc a selection field called "state". We can change the way this selection field appears. To change its view to statusbar,
    <field name="selection_field" widget="statusbar" statusbar_visible="state1,state4,state7" statusbar_colors='{"state2":"red","state3":"red","state5":"blue","state6":"blue"}'/> 

    Here state1 to state7 are the different states in the selection_field. In 'statusbar_visible' we specify the different states which should appear in the view. In 'statusbar_color' we specify the color for the status bar according to the states.
  • one2many : If there is a many2many field and we want to view it as a one2many field. Then we use 'one2many'.
  • many2many : If there is a one2many field and we want to view it as a many2many field, then we use 'many2many'
  • float_time : This is used for showing a float type field in 00:00 format
  • image : If we have a binary field for adding pictures/images, then by providing widget='image', we van view the image.
  • url : If we have a char field for adding website name, then by adding widget='url', the data in the field will have a hyperlink and by clicking on it, the website will be opened.
  • email: If we have a char field for adding the email address, and if we want to sent an e-mail to that address using our systems default mail client, use widget='email'

7 comments: