5
Getting the skeleton directory
6
------------------------------
8
Creating a new module is quickly done by copying the module called "simple" or
9
"custom" (depending on your OpenERP version) into a new directory.
11
As an example on Ubuntu:
14
$ cd /usr/lib/openerp-server/addons/
15
$ sudo cp -r custom travel
17
You will need to give yourself permissions over that new directory if you want
18
to be able to modify it: ::
20
$ sudo chown -R `whoami` travel
22
You got yourself the directory for a new module there, and a skeleton
23
structure, but you still need to change a few things inside the module's
26
Changing the default definition
27
-------------------------------
29
To change the default settings of the custom module (which is now the "travel" module),
30
get yourself into the "travel" directory and edit *__terp__.py* (with *gedit*,
31
for example, a simple text editor. Feel free to use another one) ::
36
The file looks like this:
38
.. code-block:: python
41
# Use the custom module to put your specific code in a separate module.
44
"name" : "Module for custom developments",
47
"category" : "Generic Modules/Others",
48
"website": "http://www.tinyerp.com",
49
"description": "Sample custom module where you can put your customer specific developments.",
52
"update_xml" : ["custom_view.xml"],
57
You will want to change whichever settings you feel right and get something like this:
59
.. code-block:: python
62
"name" : "Travel agency module",
65
"category" : "Generic Modules/Others",
66
"website": "http://www.tinyerp.com",
67
"description": "A module to manage hotel bookings and a few other useful features.",
70
"update_xml" : ["custom_view.xml"],
76
Note the "active" field becomes true.
78
Changing the main module file
79
-----------------------------
81
Now you need to update the custom.py script to suit the needs of your module.
82
We suggest you follow the Flash tutorial for this or download the travel agency
83
module from the 20 minutes tutorial page. ::
85
The documentation below is overlapping the two next step in this wiki tutorial,
86
so just consider them as a help and head towards the next two pages first...
88
The custom.py file should initially look like this (intentionally removing the comments):
90
.. code-block:: python
92
from osv import osv, fields
94
#class custom_material(osv.osv):
95
# _name = 'network.material'
96
# _inherit = 'network.material'
103
The '#' signs represent comments. You'll have to remove them, rename the class
104
and its attributes to something like this:
106
.. code-block:: python
108
from osv import osv, fields
110
class travel_hostel(osv.osv):
111
_name = 'travel.hostel'
112
_inherit = 'res.partner'
114
'rooms_id': fields.one2many('travel.room', 'hostel_id', 'Rooms'),
115
'quality': fields.char('Quality', size=16),
121
Ideally, you would copy that bunch of code several times to create all the
122
entities you need (travel_airport, travel_room, travel_flight). This is what
123
will hold the database structure of your objects, but you don't really need to
124
worry too much about the database side. Just filling this file will create the
125
system structure for you when you install the module.
130
You can now move on to editing the views. To do this, edit the custom_view.xml file. It should first look like this:
136
<record model="res.groups" id="group_compta_user">
137
<field name="name">grcompta</field>
139
<record model="res.groups" id="group_compta_admin">
140
<field name="name">grcomptaadmin</field>
142
<menuitem name="Administration" groups="admin,grcomptaadmin" icon="terp-stock" id="menu_admin_compta"/>
146
This is, as you can see, an example taken from an accounting system (French
147
people call accounting "comptabilité", which explains the compta bit).
149
Defining a view is defining the interfaces the user will get when accessing
150
your module. Just defining a bunch of fields here should already get you
151
started on a complete interface. However, due to the complexity of doing it
152
right, we recommend, once again, that you take a look at the 20 minutes Flash
153
tutorial or download the travel agency module example.
155
Next you should be able to create different views using other files to separate
156
them from your basic/admin view.