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"/>
Thanks Mohsin for such a detail explanation, your blog is very helpful,
ya its very helful
thanx
Bravo man Bravo, Brillent Work, everything with such details, Good work, Why didn’t I checked it before…
@yasar welcome
@waqar thanks. pray for more
nice post! thanks!
my question is: what’s the meaning of ‘sequence’ as if in
thank you very much!
@andramaya
brother sequence are used to assign a unique pattern string or number to invoices or voucher etc used in organization.
here you can fined some more detail http://doc.openerp.com/book/3/3_7/invoicing.html
thanks!
Hello,
I’m searching for how to test throw an exception on a field like this:
http://www.fileden.com/files/2010/8/22/2949090/openerp.gif
Thank you!
@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
yes but how to pass the parameter to test from the _view to the method where i have to throw the exception?
in view u have to use onchange method. and define this onchange method definition in .py format in same class
Give me an exemple please in wich i can do that!
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.
thanks
why graphs use, for graphical representation. we can use these graphs in openerp dashboards.
thank you so much!!
good job man
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 ??
use inheritance brother
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
Brother kindly include ur example code in source code tag. So that we can comment accordingly.
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” ?
combobox is used as selection in openerp, as well as many2one can also be displayed as selection (combobox)