Fix WSGI custom addons path
[odoo/odoo.git] / doc / 03_module_dev_05.rst
1 .. _module-dev-example:
2
3 ==========================
4 Example of module creation
5 ==========================
6
7 Getting the skeleton directory
8 ++++++++++++++++++++++++++++++
9
10 Create a ``travel`` directory, that will contain our addon. Create **__init__.py** file and **__openerp__.py** files.
11
12 Edit the **__openerp__.py** module manifest file:
13
14 .. code-block:: python
15     
16     {
17         "name" : "Travel agency module",
18         "version" : "1.1",
19         "author" : "Tiny",
20         "category" : "Generic Modules/Others",
21         "website" : "http://www.openerp.com",
22         "description": "A module to manage hotel bookings and a few other useful features.",
23         "depends" : ["base"],
24         "init_xml" : [],
25         "update_xml" : ["travel_view.xml"],
26         "active": True,
27         "installable": True
28     }
29
30 Changing the main module file
31 +++++++++++++++++++++++++++++
32
33 Now you need to update the travel.py script to suit the needs of your module.
34 We suggest you follow the Flash tutorial for this or download the travel agency
35 module from the 20 minutes tutorial page.  ::
36
37     The documentation below is overlapping the two next step in this wiki tutorial,
38     so just consider them as a help and head towards the next two pages first...
39
40 The travel.py file should initially look like this:
41
42 .. code-block:: python
43
44     from osv import osv, fields
45
46     class travel_hostel(osv.osv):
47            _name = 'travel.hostel'
48            _inherit = 'res.partner'
49            _columns = {
50            'rooms_id': fields.one2many('travel.room', 'hostel_id', 'Rooms'),
51            'quality': fields.char('Quality', size=16),
52            }
53            _defaults = {
54            }
55     travel_hostel()
56
57 Ideally, you would copy that bunch of code several times to create all the
58 entities you need (travel_airport, travel_room, travel_flight). This is what
59 will hold the database structure of your objects, but you don't really need to
60 worry too much about the database side. Just filling this file will create the
61 system structure for you when you install the module.
62
63 Customizing the view
64 ++++++++++++++++++++
65
66 You can now move on to editing the views. To do this, edit the custom_view.xml file. It should first look like this:
67
68 .. code-block:: xml
69
70     <openerp>
71     <data>
72         <record model="res.groups" id="group_compta_user">
73                 <field name="name">grcompta</field>
74         </record>
75         <record model="res.groups" id="group_compta_admin">
76                 <field name="name">grcomptaadmin</field>
77         </record>
78         <menuitem name="Administration" groups="admin,grcomptaadmin"
79                         icon="terp-stock" id="menu_admin_compta"/>
80     </data>
81     </openerp>
82
83 This is, as you can see, an example taken from an accounting system (French
84 people call accounting "comptabilité", which explains the compta bit).
85
86 Defining a view is defining the interfaces the user will get when accessing
87 your module. Just defining a bunch of fields here should already get you
88 started on a complete interface. However, due to the complexity of doing it
89 right, we recommend, once again, that download the travel agency module example
90 from this link http://apps.openerp.com/
91
92 Next you should be able to create different views using other files to separate
93 them from your basic/admin view.