How to create a module in OpenERP ?
It is very easy to create a module in OpenERP.
Find the below displayed screens. We will code to result this output.
Form View
Few files needs to be created compulsory. We will take an example let say – “test_module”
First of all, we will see the architecture of a typical OpenERP module.
All the modules are located in server/addons directory.
The following steps are necessary to create a new module “test_module”:
– create a subdirectory in the server/addons directory having module name test_module.
– create a module description file: __openerp__.py
– create the Python file containing the objects.
– create .xml files that download the data (views, menu entries, demo data, …).
– optionally create reports, wizards or workflows.
We will see each files introduction one by one.
The __init__.py file:
The __init__.py file is, like any Python module, executed at the start of the program. It needs to import the Python files that need to be loaded.
So, if you create a “test_module.py” file, containing the description of your objects, you have to write one line in __init__.py:
import test_module.py
The __openerp__.py file
In the created module directory, you must add a __openerp__.py file. This file, which must be in Python format, is responsible to
- determine the XML files that will be parsed during the initialization of the server, and also to
- determine the dependencies of the created module.
This file must contain a Python dictionary with the following values:
{
"name" : "Test Module",
"version" : "1.1",
"author" : "Open",
"category" : "Test Base/Test Base",
"depends" : ["base"],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["test_view.xml"],
"installable": True,
"active": True
}
The test_module.py file
from osv import osv
from osv import fields
class test_base(osv.osv):
”’Test Base Class”’
_name=‘test.base’
_columns={
‘name’:fields.char(“Name”,size=128,),
‘code’:fields.char(“Code“,size=64)
}
test_base()
The text_view.xml file
<?xml version=“1.0” encoding=“utf-8”?>
<openerp>
<data>
<record model=“ir.ui.view” id=“test_base_form”>
<field name=“name”>test.base.form</field>
<field name=“model”>test.base</field>
<field name=“type”>form</field>
<field name=“arch” type=“xml”>
<form string=“Test Base”>
<field name=“name”/>
<field name=“code”/>
</form>
</field>
</record>
<record model=“ir.ui.view” id=“test_base_tree”>
<field name=“name”>test.base.tree</field>
<field name=“model”>test.base</field>
<field name=“type”>tree</field>
<field name=“arch” type=“xml”>
<tree string=“Test Base”>
<field name=“name”/>
<field name=“code”/>
</tree>
</field>
</record>
<record model=“ir.actions.act_window” id=“action_test_seq”>
<field name=“name”>Test Base</field>
<field name=“res_model”>test.base</field>
<field name=“view_type”>form</field>
<field name=“view_mode”>tree,form</field>
</record>
<menuitem id=“menu_test_base_main” name=“Test Base”/>
<menuitem id=“menu_test_base” parent=“menu_test_base_main”
name=“Test Base” action=“action_test_seq”/>
</data>
</openerp>
Great tutorial. How different is this process for OpenERP 7.0? -Thanks!
Please check this link: http://intellectseed.wordpress.com/2012/12/05/how-to-install-new-module-in-openerp-7-0/
Thanks, but that is for how to install a module (one-click!), but I am interested in *creating* a new module.
while installing this module in openerp. the following error will be displayed File “C:\Program Files\OpenERP 7.0-20130509-231040\Server\server\openerp\addons\newm\newm.py”, line 6
SyntaxError: Non-ASCII character ‘\x94’ in file C:\Program Files\OpenERP 7.0-20130509-231040\Server\server\openerp\addons\newm\newm.py on line 6, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (newm.py, line 6)
Ok
@jyothish mohan: I got a similar error message as you did. It happened to me as I copy/pasted the code given. It so happens that the code is not using the sign “. It is using another look-alike sign which is “. You will not notice it easily. Try zooming in on the page or this reply and you will see the difference. I am putting both here side by side ” “. You need to replace the one in the code with the one found on the keyboard which is ” (please enlarge to see difference).
There is also one typo in __openerp__.py; It references the file test_view.xml, but the author suggested to create a file called text_view.xml. This will give you an IOError of type “File not found…”. You need to have the same name in the reference as for the file.
Next typo is still in file __openerp__.py. It says ”’Test Base Class”’. See how the ” and ’ are interchanged at beginning and end. First use the correct sign” and correct order like this ‘”Test Base Class”‘.
Once you install this module, you should see the button TEST BASE on the top main menu bar. I am using OpenERP 6.1.1.
Apart from that, thanks for the tutorial.
Another typo is in file __init__.py. It says import test_module.py. Kindly change it to: import test_module
I meant to say change it to import text_module
Reblogged this on Researcher's Blog and commented:
How to create a module in OpenERP ?
Someone told me on IRC that modules for 6.x are incompatible with 7.x is this true?
Hello !
If there are only python files then sometimes 6.x module will work.
But because of changes in view structure, it may not work.
Thanks,
Acespritech Solutions Pvt. Ltd.
thanx for your post
it import without error but when i try to search and install from openerp window that time it was not found
when i implement your code and import like this import test_module
then it shows me error
Importing test modules … Traceback (most recent call last):
File “C:\eclipse-standard-kepler-R-win32\eclipse\plugins\org.python.pydev_2.8.2.2013090511\pysrc\pydev_runfiles.py”, line 432, in __get_module_from_str
mod = __import__(modname)
File “C:\Users\Ishtiaq\workspace\openerp-7.0-20130715-231029\openerp\addons\testmodulue\test_module.py”, line 7
fro osv import osv
^
SyntaxError: invalid syntax
ERROR: Module: test_module could not be imported (file: C:/Users/Ishtiaq/workspace/openerp-7.0-20130715-231029/openerp/addons/testmodulue/test_module.py).
done.
———————————————————————-
Ran 0 tests in 0.000s
OK
Hello,
any chance of knowing for odoo 8 or 9?
Thanks,
Vish