Home > Eclipse, Financial Accounting, OpenERP, Postgresql, Python, XML > Modules Development in OpenERP: View, Events, Menu and Actions

Modules Development in OpenERP: View, Events, Menu and Actions

In this tutorial I will explain the syntax of views, events, menus and actions in openERP with some examples.
For detail we can check the documentation of design elements in openERP from
http://doc.openerp.com/developer/2_6_views_events/views/design_element.html

List of syntax and examples of different control in OpenERP
1. View file in OpenERP
2. Button in OpenERP
3. Menu Item in OpenERP
4. Tree View in OpenERP
5. Form View in OpenERP
6. View Action in OpenERP
7. Complete form view in OpenERP

1. View file in openERP
a. XML Declaration
b. OpenERP body tag

Syntax:

<?xml version="1.0" encoding="${encoding}"?>
<openerp>
    <data>
    	[view definitions]
    </data>
</openerp>


Example of view file in openERP

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

    </data>
</openerp>

2. Button In OpenERP
a. Type Object
b. Type Wizard
c. Type Workflow

Syntax:
a. Type Object

<button name="${function_name}" states="${state}" string="${string}" type="object" icon="${icon}"/>

Example of type object

<button name="create_period" states="draft" string="Create Monthly Periods" type="object"/>

b. Type Wizard

<button name='%(${wizard_id})d' type='action' string='${string}' states='${state}' icon="${icon}"/>
parent="account.menu_finance_charts"  type="wizard"/>

c. Type Workflow

<button name='%(${wizard_id})d' type='action' string='${string}' states='${state}' icon="${icon}"/>

Example of type workflow

<button name="confirm" states="draft" string="Confirm" type="workflow"/>


3. Menu Item in OpenERP

a. Parent
b. Type action
c. Type action with wizard

Syntax:
a. Parent

<menuitem id="${object_name}_menu" name="${object_name}" />

Example of Parent

<menuitem icon="terp-account" id="menu_finance" name="Financial Management"/>
<menuitem id="menu_finance_configuration" name="Configuration" parent="menu_finance" sequence="1"/>

b. Type Action

<menuitem id="${object_name}_menu" name="${objectname}" parent="${cursor}" action="action_${object_name}_tree_view"/>

Example of Type Action

<menuitem action="action_account_fiscalyear_form" id="menu_action_account_fiscalyear_form" parent="next_id_23"/>

c. Type action with wizard

<menuitem id="${object_name}_menu" name="${ob
action="action_${object_name}_tree_view" type="object"  />

Example of type action with type

<menuitem icon="STOCK_JUSTIFY_FILL" action="action_move_journal_line_form" id="menu_action_move_journal_line_form" parent="account.menu_finance_entries" type="wizard" sequence="5"/>

4. Tree View in OpenERP
a. Simple Tree View
b. Inherit Tree View

Syntax
a. Simple Tree View

 <record model="ir.ui.view" id="${object_name}_tree_view">
                <field name="name">${objectname}.tree</field>
                <field name="model">${objectname}</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="${tree_string}">
                        <field name="name"/>
                    </tree>
                </field>
</record>

Example of simple tree view

<record id="view_move_line_tree" model="ir.ui.view">
            <field name="name">account.move.line.tree</field>
            <field name="model">account.move.line</field>
            <field name="type">tree</field>
            <field eval="4" name="priority"/>
            <field name="arch" type="xml">
                <tree string="Account Entry Line" editable="top" on_write="_on_create_write">
                    <field name="date"/>
                    <field name="period_id"/>
                    <field name="move_id"/>
                    <field name="ref"/>
                    <field name="invoice"/>
                    <field name="name"/>
                    <field name="partner_id"/>
                    <field name="account_id" domain="[('journal_id','=',journal_id)]"/>
                    <field name="journal_id"/>
                    <field name="debit" sum="Total debit"/>
                    <field name="credit" sum="Total credit"/>
                    <field name="account_tax_id" groups="base.group_extended"/>
                    <field name="analytic_account_id"/>
                    <field name="amount_currency" groups="base.group_extended"/>
                    <field name="currency_id" groups="base.group_extended"/>
                    <field name="state"/>
                    <field name="reconcile_id"/>
                    <field name="reconcile_partial_id" groups="base.group_extended"/>
                </tree>
            </field>
        </record>

b. Inherit Tree View

<record model="ir.ui.view" id="${object_name}_tree_view">
                <field name="name">${objectname}.tree</field>
                <field name="model">${objectname}</field>
                <field name="type">tree</field>
                <field name="inherit_id" ref="${view_name}"/>
                <field name="arch" type="xml">
                    <tree string="${tree_string}">
                        <field name="${field_name}" position="${position}"/>
                        	<field name="${new_field}"/>
                    </tree>
                </field>
 </record>

Example of Inherit Tree View

<record id="view_move_line_tree" model="ir.ui.view">
            <field name="name">account.move.line.form.inherit</field>
            <field name="model">account.move.line</field>
            <field name="type">tree</field>
            <field name="inherit_id" ref="account.view_move_line_tree"/>
            <field name="arch" type="xml">
<field name="invoice" position="replace">
		<field name="voucher_invoice"/>
	</field>
            </field>
 </record>

5. Form View in openERP
a. Simple form view
b. Inherit form view

Syntax:
a. Simple Form View

<record model="ir.ui.view" id="${object_name}_form_view">
                <field name="name">${objectname}.form</field>
                <field name="model">${objectname}</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="${form_string}">
                        <field name="name" select="1"/>
                    </form>
                </field>
 </record>

Example of simple form view

<record id="view_invoice_line_form" model="ir.ui.view">
            <field name="name">account.invoice.line.form</field>
            <field name="model">account.invoice.line</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Invoice Line">
                    <notebook>
                        <page string="Line">
                            <field name="product_id" on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit)" select="1"/>
                            <field name="uos_id"/>
                            <field name="quantity" select="1"/>
                            <field name="price_unit" select="1"/>
                            <field name="discount"/>
                            <field colspan="4" name="name" select="1"/>
                            <field colspan="4" name="origin" select="1"/>
                            <field domain="[('company_id', '=', parent.company_id), ('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]" name="account_id" on_change="onchange_account_id(parent.fiscal_position,account_id)" groups="base.group_user"/>
                            <field domain="[('type','<>','view'), ('company_id', '=', parent.company_id)]" name="account_analytic_id" groups="base.group_user"/>
                            <newline/>
                            <field name="price_subtotal"/>
                            <field colspan="4" name="invoice_line_tax_id" context="{'type':parent.type}" domain="[('parent_id','=',False),('company_id', '=', parent.company_id)]"/>
                        </page>
                        <page string="Notes">
                            <field colspan="4" name="note" nolabel="1"/>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

b. Inherit Form View

<record model="ir.ui.view" id="${object_name}_form_view">
                <field name="name">${objectname}.form</field>
                <field name="model">${objectname}</field>
                <field name="type">form</field>
                <field name="inherit_id" ref="${view_name}"/>
                <field name="arch" type="xml">
                    <form string="${form_string}">
                        <field name="${field_name}" position="${position}"/>
                        	<field name="${new_field}"/>
                    </form>
                </field>
</record>

Example of inherit form view

<record model="ir.ui.view" id="view_account_invoice_asset_form">
        <field name="name">account.invoice.line.form</field>
        <field name="model">account.invoice.line</field>
        <field name="inherit_id" ref="account.view_invoice_line_form"/>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <field name="price_subtotal" position="after">
                <field name="asset_method_id" context="name=name" domain ="[('state','in', ['draft','open','suppressed','depreciated'])]" on_change="asset_method_id_change(asset_method_id, parent.type)"/>
            </field>
        </field>
    </record>

6. View Action in OpenERP

 <record model="ir.actions.act_window" id="action_${object_name}_tree_view">
                <field name="name">${objectname}</field>
                <field name="type">ir.actions.act_window</field>
                <field name="res_model">${objectname}</field>
<!-- <field name="domain">[('field_name','condition',criteria)]</field>-->
                <field name="view_type">form</field>
                <field name="view_mode">tree,form</field>
                <field name="view_id" ref="${object_name}_tree_view"/>
</record>

Example View Action

<record id="action_move_line_select" model="ir.actions.act_window">
            <field name="name">Entry Lines</field>
            <field name="res_model">account.move.line</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="view_move_line_tree"/>
</record>

7. Complete form view in OpenERP
a. Calendar view
b. Graph view
c. List/Tree view
4. Form View
e. Action View
f. Menu Item

Syntax:
a. Calendar view Syntax
Example of calendar view

<record id="view_invoice_line_calendar" model="ir.ui.view">
            <field name="name">account.invoice.calendar</field>
            <field name="model">account.invoice</field>
            <field name="type">calendar</field>
            <field name="arch" type="xml">
                <calendar string="Invoices" color="journal_id" date_start="date_invoice">
                    <field name="partner_id"/>
                    <field name="amount_total"/>
                </calendar>
            </field>
 </record>

b. Graph view
Example of graph view

        <record model="ir.ui.view" id="view_invoice_graph">
            <field name="name">account.invoice.graph</field>
            <field name="model">account.invoice</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Invoices" type="bar">
                    <field name="partner_id"/>
                    <field name="amount_total" operator="+"/>
                </graph>
            </field>
        </record>

c. List/Tree View Syntax

            <record model="ir.ui.view" id="${object_name}_tree_view">
                <field name="name">${objectname}.tree</field>
                <field name="model">${objectname}</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="${tree_string}">
                        <field name="name"/>
                    </tree>
                </field>
            </record>

Example of list/tree view example

        <record id="view_account_fiscalyear_tree" model="ir.ui.view">
            <field name="name">account.fiscalyear.tree</field>
            <field name="model">account.fiscalyear</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Fiscalyear">
                    <field name="code"/>
                    <field name="name"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

d. Form View Syntax

            <record model="ir.ui.view" id="${object_name}_form_view">
                <field name="name">${objectname}.form</field>
                <field name="model">${objectname}</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="${form_string}">
                        <field name="name" select="1"/>
                    </form>
                </field>
            </record>

Example of form view

        <record id="view_account_fiscalyear_form" model="ir.ui.view">
            <field name="name">account.fiscalyear.form</field>
            <field name="model">account.fiscalyear</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Fiscalyear">
                    <field name="name" select="1"/>
                    <field name="code" select="1"/>
                    <field name="date_start"/>
                    <field name="date_stop"/>
                    <field name="end_journal_period_id"/>
                    <separator colspan="4" string="States"/>
                    <field name="state" select="1" readonly="1"/>
                </form>
            </field>
        </record>

e. Action View Syntax

            <record model="ir.actions.act_window" id="action_${object_name}_tree_view">
                <field name="name">${objectname}</field>
                <field name="type">ir.actions.act_window</field>
                <field name="res_model">${objectname}</field>
 <!-- <field name="domain">[('field_name','condition',criteria)]</field>-->
                <field name="view_type">form</field>
                <field name="view_mode">tree,form</field>
                <field name="view_id" ref="${objectname}_tree_view"/>
            </record>

Example of action view

       <record id="action_account_fiscalyear_form" model="ir.actions.act_window">
            <field name="name">Fiscal Years</field>
            <field name="res_model">account.fiscalyear</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

f. Menu Item Syntax

<menuitem id="${object_name}_menu" name="${objectname}" parent="${cursor}" action="action_${object_name}_tree_view"/>
Example of menu item
        <menuitem id="next_id_23" name="Periods" parent="account.menu_finance_accounting"/>
        <menuitem action="action_account_fiscalyear_form" id="menu_action_account_fiscalyear_form" parent="next_id_23"/>
  1. Muhammad Yasar Khan
    October 6, 2010 at 6:44 am

    Thanks Mohsin for such a detail explanation, your blog is very helpful,

    • SHAHID ISLAM
      April 18, 2011 at 9:50 am

      ya its very helful

    • January 17, 2012 at 5:06 am

      thanx

  2. November 2, 2010 at 9:59 am

    Bravo man Bravo, Brillent Work, everything with such details, Good work, Why didn’t I checked it before…

  3. November 4, 2010 at 2:53 pm

    @yasar welcome
    @waqar thanks. pray for more

  4. andramaya
    December 8, 2010 at 10:28 am

    nice post! thanks!
    my question is: what’s the meaning of ‘sequence’ as if in

    thank you very much!

  5. med
    March 18, 2011 at 2:44 pm

    Hello,
    I’m searching for how to test throw an exception on a field like this:

    Thank you!

    • March 18, 2011 at 5:50 pm

      @med
      use except_orm with raise like below;

      from tools.translate import _
      raise except_orm(_(‘Msg Bos Title’), _(‘Title explanation’))

      ur can define above lines in exception handling and ur custom function etc

  6. med
    March 22, 2011 at 9:45 am

    yes but how to pass the parameter to test from the _view to the method where i have to throw the exception?

    • March 22, 2011 at 10:28 am

      in view u have to use onchange method. and define this onchange method definition in .py format in same class

  7. Mohamed
    March 22, 2011 at 11:53 am

    Give me an exemple please in wich i can do that!

  8. kashdav
    August 20, 2011 at 12:12 pm

    Hello, I have read your similar posts on OpenERP & they are very helpful. I have a query related to ‘graph’ view. The ‘form’ & ‘tree’ view are self explanatory (as read from the OpenERP developer guide) but what is the purpose of the ‘graph’ view?

    Might seem an insignificant question but I have browsed through the demo code & not been able to grasp the difference. All on line help tells the ‘how’ but not the ‘why’ & ‘what’ of it. Your help would be much valuable. Thanks.

    • August 20, 2011 at 9:08 pm

      thanks
      why graphs use, for graphical representation. we can use these graphs in openerp dashboards.

  9. Luu Diep
    September 17, 2011 at 6:02 pm

    thank you so much!!

  10. pravitha
    January 27, 2012 at 5:48 am

    good job man

  11. siva
    February 22, 2012 at 6:52 am

    i hav added another tab in the sales order section .. but i was not able to see any change, I hav updated the module .. can any one plz help me ..

    Can any one plz guide me how to change the xml file to change the view .. any link for reference ??

    • February 22, 2012 at 5:39 pm

      use inheritance brother

  12. jihene
    March 9, 2012 at 12:57 pm

    Thanks Mohsin for all this informations ,but you can help me I create a new module named paiefouledhIuse open erp v6 and python 2.7 I have installed it in Openerp v6 the list it shown but the form is not shown and I don’t know where is the problem please help me !!!!!
    This is the xml code:

    paiefouledh.tree
    paiefouledh
    tree

    paiefouledh.form
    paiefouledh
    form

    paiefouledh
    paiefouledh
    form
    tree,form

    • March 9, 2012 at 4:45 pm

      Brother kindly include ur example code in source code tag. So that we can comment accordingly.

  13. Merry
    April 24, 2012 at 10:50 am

    Thank you for you effort to help others, it’s really good job .
    I’m new in Open ERP and that was helpful to me. I just want to know how can i display a “combobox” ?

    • May 2, 2012 at 6:12 am

      combobox is used as selection in openerp, as well as many2one can also be displayed as selection (combobox)

  14. August 23, 2012 at 6:17 am

    Hi, first of all your thank you for the samples, your samples have been usefull to me.

    can you help me with the treeview, as with your sample it can be editable using: editable=”top” attribute. can I make this conditional only when transaction is not done?

    also this is the tree of of stock move of stock picking for internal moves

    Thnks

  15. January 3, 2013 at 10:21 am

    Mohsin vaia , please give me your email address.I can’t make a connection with database from pos.xml

  16. January 3, 2013 at 10:23 am

    I want to add an option value in pos.xml and retrive the customer field from database.how can I do that

  17. March 19, 2013 at 12:21 pm

    thanks moshin & need to add menu item to my module
    (for copy & not move from one to another)how to implement that ?

    for ex:

    adding this in my view.xml enough to do.?

  18. priyanka
    March 29, 2013 at 8:15 am

    Hi moshin,
    Please add the Tree view in Form view example, with onchange function to load values to child object fields

    • sumitra barua
      May 29, 2013 at 3:23 am

      Dear Already I know about it and I am a regular programmer on openerp.Thanks for your suggestion. Sumitra

      ________________________________

  19. May 20, 2014 at 8:14 am

    Thanks for sharing the code on OpenERP worth bookmarking this website for future references

    Recently they rebranded OpenERP to Odoo

    Thanks
    Globalteckz Team
    http://www.globalteckz.com

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: