Creating a module in OpenErp 7.0 is quite different from how it has been in 6.1. Already discussed earlier to create a module in version 6.1, its time to throw some light on a basic module created in OpenErp 7.0.
To start with the basic structure its same as usual:
__init__.py
__openerp__.py
model.py
model_view.xml
I created a module named test.
The __init__.py loads your model classes as usual.
import demo
The openerp.py is slightly different. Here the attributes have been changed and to parse the view files the attribute is now data.
{
'name' : 'Demo',
'version' : '1.1',
'author' : 'OpenERP SA',
'category' : 'Tools',
'description' : 'First module in 7.0',
'website': 'http://www.evontech.com',
'images' : [],
'depends' : ['base_setup'],
'data': ['demo_view.xml'],
'installable': True,
'auto_install': False,
}
In your model.py there is the only difference in importing the packages, rest is the same. Note line
from openerp.osv import fields, osv, orm
import time
from lxml import etree
import openerp.addons.decimal_precision as dp
import openerp.exceptions
from openerp import netsvc
from openerp import pooler
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _
class demo(osv.osv):
_name = 'demo'
_columns = {
'name':fields.char('Name', size=50),
'active':fields.boolean('Active'),
'age':fields.integer('Age'),
'gender':fields.selection([('male','Male'),('female','Female')],'Gender'),
'job':fields.many2one('occupation','Occupation'),
'note':fields.text('Note',size=300),
}
demo()
class occupation(osv.osv):
_name = 'occupation'
_columns = {
'name':fields.char('Occupation', size=100),
'active':fields.boolean('Active'),
}
occupation()
Now time to create a view file. Here the major changes will be:
a) when defining the form you have to mention the version attribute as version="7.0"
b) We don't create menus the same way here, you each menu item should have its own action and that too defined in a different manner, note the action_job_tree in the action record.
c) Providing help on a field is a new thing, note: field help of type="html"
with
class="oe_view_nocontent_create"
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_demo_tree" model="ir.ui.view">
<field name="name">demo.tree</field>
<field name="model">demo</field>
<field name="arch" type="xml">
<tree string="Demo">
<field name="name"/>
<field name="gender"/>
<field name="job"/>
</tree>
</field>
</record>
<record id="view_demo_form" model="ir.ui.view">
<field name="name">demo.form</field>
<field name="model">demo</field>
<field name="arch" type="xml">
<form string="Demo" version="7.0">
<group>
<field name="name"/>
<field name="age"/>
<field name="gender"/>
<field name="job"/>
<field name="active"/>
</group>
<notebook>
<page string="Extra Info">
<field name="note"/>
</page>
</notebook>
</form>
</field>
</record>
<record id="view_job_tree" model="ir.ui.view">
<field name="name">job.tree</field>
<field name="model">occupation</field>
<field name="arch" type="xml">
<tree string="Occupations">
<field name="name"/>
</tree>
</field>
</record>
<record id="view_job_form" model="ir.ui.view">
<field name="name">job.form</field>
<field name="model">occupation</field>
<field name="arch" type="xml">
<form string="Occupations">
<field name="name"/>
<field name="active"/>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_demo">
<field name="name">New Name</field>
<field name="res_model">demo</field>
</record>
<record model="ir.actions.act_window" id="action_job">
<field name="name">Occupations</field>
<field name="res_model">occupation</field>
</record>
<record id="action_demo_tree" model="ir.actions.act_window">
<field name="name">Names</field>
<field name="res_model">demo</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="view_id"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to record a new entry.
</p>
</field>
</record>
<record id="action_job_tree" model="ir.actions.act_window">
<field name="name">Occupations</field>
<field name="res_model">occupation</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field eval="False" name="view_id"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to record a new occupation.
</p>
</field>
</record>
<menuitem name="Demo" id="menu_action_demo_form" action="action_demo" sequence="1"/>
<menuitem id="menu_action_demo" parent="menu_action_demo_form" action="action_demo" sequence="1"/>
<menuitem id="menu_action_demo1" parent="menu_action_demo" action="action_demo_tree" sequence="1"/>
<menuitem id="menu_action_job" parent="menu_action_demo_form" action="action_job" sequence="2"/>
<menuitem id="menu_action_job1" parent="menu_action_job" action="action_job_tree" sequence="2"/>
</data>
</openerp>
0 Comment(s)