An empty module in odoo contains at least two files.
1] __init__.py
2] __openerp__.py
__init__.py contains the import information for various python files in the module where as __openerp__.py is a manifest file.
Content of __openerp__.py file :
# -*- coding: utf-8 -*-
{
# Display name for module
'name': "Employee",
# A brief summary of the module
'summary': """Employee Management""",
# Description for the module
'description': """
Employee module for managing:
- attendance
- salary
- leave
""",
'author': "XYZ Company",
'website': "http://www.xyzcompany.com",
# Categories can be used to filter modules in modules listing
'category': 'Test',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'templates.xml',
],
# only loaded in demonstration mode
'demo': [
#'demo.xml',
],
}
Creation of empty module is fine but it will not serve any purpose, so along with these files we have models as well as views.
Models are created by using .py file and view is created by using .xml file in Odoo.
The below example illustrate the simple module creation in Odoo.
1] __init__.py
import employee.py
2] __openerp__.py
Code for __openerp__.py is shown above.
3] employee.py
from openerp import models, fields
class res_employee(models.Model):
# Model name
_name = 'res.employee'
# Model fields
name = fields.Char(string = 'Name', required = True)
email_id = fields.Char(string = 'Email Id')
4] templates.xml<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- window action -->
<!--
The following tag is an action definition for a "window action",
that is an action opening a view or a set of views
-->
<record model="ir.actions.act_window" id="employee_action">
<field name="name">Employee</field>
<field name="res_model">res.employee</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the Employee
</p>
</field>
</record>
<!-- top level menu: no parent -->
<menuitem id="main_menu" name="Employee Detail"/>
<!-- A first level in the left side menu is needed
before using action= attribute -->
<menuitem id="employee_menu" name="Employee"
parent="main_menu"/>
<!-- the following menuitem should appear after
its parent employee_menu and after its
action employee_action -->
<menuitem id="personal_menu" name="Personal" parent="employee_menu"
action="employee_action"/>
</data>
</openerp>
Create a empty directory in odoo server addons directory and save all of this files into that directory. Start odoo server and install the module.
No comments:
Post a Comment