~xrg/openobject-doc/trunk-xrg

« back to all changes in this revision

Viewing changes to source/contribute/developing_modules.rst

  • Committer: TruongSinh Tran
  • Date: 2009-07-17 18:59:45 UTC
  • Revision ID: truongsinh@vipescoserver-20090717185945-ajjp3zso6xh5jddm
[FIX]private issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
Developing modules
 
3
-------------------
 
4
 
 
5
.. index::
 
6
   single: modules development
 
7
.. 
 
8
 
 
9
Introduction
 
10
++++++++++++
 
11
 
 
12
Here you will found informations about the organisation of the community in
 
13
OpenERP project. It include a description of the different tools used, the role
 
14
of the differents actors, and the different process for improvement management.
 
15
 
 
16
The whole organisation is managed through our launchpad projects: http://launchpad.net
 
17
Our projects on launchpad are currently organised like this:
 
18
 
 
19
 
 
20
+----------------------------+----------------------------------------------+--------------------------------------------+
 
21
| **Project name**           | **URL**                                      | **Description**                            |
 
22
+============================+==============================================+============================================+
 
23
|                            |                                              |                                            |
 
24
| **openobject**             | https://launchpad.net/openobject             | the main super-project (group) where all   |
 
25
|                            |                                              | bugs, features and faq are managed         |
 
26
|                            |                                              |                                            |
 
27
+----------------------------+----------------------------------------------+--------------------------------------------+
 
28
|                            |                                              |                                            |
 
29
| **openobject-bi**          | https://launchpad.net/openobject-bin         | business intelligence project              |
 
30
|                            |                                              |                                            |
 
31
+----------------------------+----------------------------------------------+--------------------------------------------+
 
32
|                            |                                              |                                            |
 
33
| **openobject-server**      | https://launchpad.net/openobject-server      |  the openobject server                     |
 
34
|                            |                                              |                                            |
 
35
+----------------------------+----------------------------------------------+--------------------------------------------+
 
36
|                            |                                              |                                            |
 
37
| **openobject-client**      | https://launchpad.net/openobject-client      | the openobject application client (gtk)    |
 
38
|                            |                                              |                                            |
 
39
+----------------------------+----------------------------------------------+--------------------------------------------+
 
40
|                            |                                              |                                            |
 
41
| **openobject-client-web**  | https://launchpad.net/openobject-client-web  | the openobject web client (previously      |
 
42
|                            |                                              | called eTiny)                              |
 
43
|                            |                                              |                                            |
 
44
+----------------------------+----------------------------------------------+--------------------------------------------+
 
45
|                            |                                              |                                            |
 
46
| **openobject-addons**      | https://launchpad.net/openobject-addons      | the project for all modules about          |
 
47
|                            |                                              | openobject                                 |
 
48
|                            |                                              |                                            |
 
49
+----------------------------+----------------------------------------------+--------------------------------------------+
 
50
|                            |                                              |                                            |
 
51
| **openerp**                | https://launchpad.net/openerp                | packaging around openobject (a selection   |
 
52
|                            |                                              | of modules to build applications)          |
 
53
|                            |                                              |                                            |
 
54
+----------------------------+----------------------------------------------+--------------------------------------------+
 
55
 
 
56
Getting Sources
 
57
+++++++++++++++
 
58
 
 
59
Please refer to :ref:`how-to-get-the-latest-trunk-source-code-link` in the Bazaar section
 
60
 
 
61
If you don't know the Bazaar version control system, please read the :ref:`documentation on Bazaar <bazaar-link>`
 
62
 
 
63
.. _coding-guidelines-link:
 
64
 
 
65
Coding Guidelines
 
66
+++++++++++++++++
 
67
 
 
68
Development Guidelines
 
69
""""""""""""""""""""""
 
70
 
 
71
Modules
 
72
^^^^^^^
 
73
 
 
74
Organisation of files in modules
 
75
################################
 
76
 
 
77
.. === Organisation of files in modules ===
 
78
 
 
79
The structure of a module should be like this::
 
80
 
 
81
 /module_name/
 
82
 /module_name/__init__.py
 
83
 /module_name/__terp__.py
 
84
 /module_name/module.py
 
85
 /module_name/module_view.xml
 
86
 /module_name/module_wizard.xml
 
87
 /module_name/module_report.xml
 
88
 /module_name/module_data.xml
 
89
 /module_name/module_demo.xml
 
90
 /module_name/module_security.xml
 
91
 /module_name/wizard/
 
92
 /module_name/wizard/__init__.py
 
93
 /module_name/wizard/wizard_name.py
 
94
 /module_name/wizard/wizard_name_view.xml
 
95
 /module_name/wizard/wizard_name_workflow.xml
 
96
 /module_name/report/
 
97
 /module_name/report/__init__.py
 
98
 /module_name/report/report_name.sxw
 
99
 /module_name/report/report_name.rml
 
100
 /module_name/report/report_name.py
 
101
 
 
102
Objects and fields namings
 
103
##########################
 
104
 
 
105
Security
 
106
########
 
107
 
 
108
Each object defined in your module must have at least one security rule
 
109
defined on it to make it accessible.
 
110
 
 
111
.. describe:: Preventing SQL Injection:
 
112
 
 
113
 
 
114
Care must be taken not to introduce SQL injection vulnerabilities to SQL
 
115
queries. SQL Injection is a kind of vulnerability in which the user is able to
 
116
introduce undesirable clauses to a SQL query (such as circumventing filters or
 
117
executing **UPDATE** or **DELETE** commands) due to incorrect quoting in
 
118
the application.
 
119
 
 
120
In order to prevent SQL injection you need to be cautious when constructing SQL
 
121
query strings. Good advices are to use %d and %f when only numbers are to be
 
122
substituted and always use psycopg formatting parameters. For example the
 
123
following expression is incorrect:
 
124
 
 
125
.. code-block:: python
 
126
 
 
127
  cr.execute( "SELECT * FROM table_name WHERE name='%s'" % client_supplied_string )
 
128
 
 
129
.. 
 
130
 
 
131
and 
 
132
 
 
133
.. code-block:: python
 
134
 
 
135
  cr.execute( "SELECT * FROM table_name WHERE name=%s", client_supplied_string )
 
136
 
 
137
.. 
 
138
 
 
139
should be used instead.
 
140
 
 
141
Development
 
142
^^^^^^^^^^^
 
143
 
 
144
Coding Guidelines
 
145
#################
 
146
 
 
147
Follow Python PEP 8: http://www.python.org/dev/peps/pep-0008/
 
148
 
 
149
Reporting
 
150
^^^^^^^^^
 
151
 
 
152
General Style
 
153
#############
 
154
 
 
155
  * use the Helvetica font everywhere
 
156
  * margins (in millimeters):
 
157
 
 
158
    - top: 14
 
159
    - bottom: 16
 
160
    - left: between 12 and 13 to allow punching holes without punching in the text area
 
161
    - right: between 12 and 13
 
162
 
 
163
.. note:: the line separator between the header and the body can overlap slightly in the left and right margins: up to 9 millimeters on the left and up to 12 millimeters on the right
 
164
 
 
165
.. 
 
166
 
 
167
  * for Titles use the font *Heveltica-Bold* with the size *14.5*
 
168
 
 
169
  * put the context on each report: example, for the report account_balance: the context is the fiscal year and periods
 
170
 
 
171
  * for the name of cells: use Capital Letter if the name contains more than one word (ex: Date Ordered)
 
172
  * content and name of cells should have the same indentation
 
173
 
 
174
  * for report, we can define two kinds of arrays:
 
175
 
 
176
    - array with general information, like reference, date..., use:
 
177
 
 
178
      + *Bold-Helvetica* and size=8 for cells name
 
179
      + *Helvetica* size="8" for content
 
180
    - array with detailed information, use:
 
181
 
 
182
      + *Helvetica-Bold* size *9* for cells names
 
183
      + *Helvetica* size *8* for content
 
184
 
 
185
.. describe:: Headers and footers for internal reports:
 
186
 
 
187
  * Internal report = all accounting reports and other that have only internal use (not sent to customers)
 
188
  * height of headers should be shorter
 
189
  * take off corporate header and footer for internal report (Use a simplified header for internal reports: Company's name, report title, printing date and page number)
 
190
 
 
191
  * header:
 
192
 
 
193
    - company's name: in the middle of each page 
 
194
    - report's name: is printed centered after the header
 
195
    - printing date: not in the middle of the report, but on the left in the header
 
196
    - page number: on each page, is printed on the right. This page number should contain the current page number and the total of pages. Ex: page 3/15
 
197
  * footer:
 
198
 
 
199
    - to avoid wasting paper, we have taken off the footer
 
200
 
 
201
.. describe:: table line separator:
 
202
 
 
203
* it's prettier if each line in the table have a light grey line as separator
 
204
* use a grey column separator only for array containing general information
 
205
 
 
206
.. describe:: table breaking
 
207
 
 
208
  * a table header should at least have two data rows (no table header alone at the bottom of the page)
 
209
  * when a big table is broken, the table header is repeated on every page
 
210
 
 
211
.. describe:: how to differentiate parents and children ?
 
212
 
 
213
  * When you have more than one level, use these styles:
 
214
 
 
215
  - for the levels 1 and 2:fontSize="8.0" fontName="Helvetica-Bold"
 
216
  - from the third level, use:fontName="Helvetica" fontSize="8.0" and increase the indentation with  13 (pixels) for each level
 
217
  - underline sums when the element is a parent
 
218
 
 
219
Modules
 
220
"""""""
 
221
 
 
222
Naming Convention
 
223
^^^^^^^^^^^^^^^^^
 
224
 
 
225
The name of the module are all lowercase, each word separated by underscrores.
 
226
Start always by the most relevant words, which are preferably names of others
 
227
modules on which it depends.
 
228
 
 
229
Exemple:
 
230
 
 
231
  * account_invoice_layout
 
232
 
 
233
Information Required
 
234
^^^^^^^^^^^^^^^^^^^^
 
235
 
 
236
Each module must contains at least:
 
237
 
 
238
  * name
 
239
  * description
 
240
 
 
241
Modules Description
 
242
^^^^^^^^^^^^^^^^^^^
 
243
 
 
244
Dependencies
 
245
^^^^^^^^^^^^
 
246
 
 
247
Each module must contains:
 
248
 
 
249
  * A list of dependencies amongst others modules: ['account','sale']
 
250
 
 
251
    - Provide only highest requirement level, not need to set ['account','base','product','sale']
 
252
  * A version requirement string where base is the Open ERP version as a Python expression
 
253
 
 
254
    - account>=1.0 && base=4.4
 
255
 
 
256
Module Content
 
257
^^^^^^^^^^^^^^
 
258
 
 
259
Each module must contains dema data for every object defined in the module.
 
260
 
 
261
If you implemented workflows in the module, create demo data that passes
 
262
most branches of your workflow. You can use the module recorder to help you
 
263
build such demo data.
 
264
 
 
265
User Interface Guidelines
 
266
"""""""""""""""""""""""""
 
267
 
 
268
Menus
 
269
^^^^^
 
270
 
 
271
Organising menus
 
272
################
 
273
 
 
274
Here is a good example:
 
275
 
 
276
  * Invoices (list)
 
277
 
 
278
    - Customer Invoices (list)
 
279
 
 
280
      + Draft Customer Invoices (list)
 
281
      + Open Customer Invoices (list)
 
282
      + New Customer Invoice (form)
 
283
    - Supplier Invoices
 
284
 
 
285
      + ...
 
286
 
 
287
Add a *New ...* menu only if the user requires it, otherwise, open all
 
288
menus as lists. The *New ...* menu open as a form instead of a list. For example,
 
289
don't put *New ...* in a menu in the configuration part.
 
290
 
 
291
If you use folders that are clickable, their child must be of the
 
292
same object type. (we suppose that inheritancies are the same objects)
 
293
 
 
294
List are plurals:
 
295
 
 
296
  * *Customer Invoice*, should be *Customer Invoices*
 
297
 
 
298
 
 
299
If you want to create menu that filters on the user (*All* and *My*) put them at the same level:
 
300
 
 
301
  * Tasks
 
302
  * My Tasks
 
303
 
 
304
And not:
 
305
 
 
306
  * Tasks
 
307
 
 
308
    - My Tasks
 
309
 
 
310
Avoid Abbreviations in menus if possible. Example:
 
311
 
 
312
  * BoM Lines -> Bill of Materials Lines
 
313
 
 
314
Reporting Menu
 
315
##############
 
316
 
 
317
The dashboard menu must be under the report section of each main menu
 
318
 
 
319
  * Good: Sales Management / Reporting / Dashboards / Sales Manager
 
320
  * Bad: Dashboard / Sales / Sales Manager
 
321
 
 
322
If you want to manage the *This Month/ALL months* menu, put them at the latest level:
 
323
 
 
324
  * Reporting/Timesheet by User/All Month
 
325
  * Reporting/Timesheet by User/This Month
 
326
 
 
327
Icons in the menu
 
328
#################
 
329
 
 
330
  * The icon of the menu, must be set according to the end action of the wizard, example:
 
331
 
 
332
    - wizard that prints a report, should use a report icon and not a wizard
 
333
    - wizard that opens a list at the end, should use a list icon and not a wizard
 
334
 
 
335
Order of the menus
 
336
##################
 
337
 
 
338
The configuration menu must be at the top of the list, use a sequence=0
 
339
 
 
340
The *Reporting* menu is at the bottom of the list, use a sequence=50.
 
341
 
 
342
Common Mistakes
 
343
###############
 
344
 
 
345
  * Edit Categories -> Categories
 
346
  * List of Categories -> Categories
 
347
 
 
348
Views
 
349
^^^^^
 
350
 
 
351
Objects with States
 
352
###################
 
353
 
 
354
  * The state field, if any, must be at the bottom left corner of the view
 
355
  * Buttons to make the state change at the right of this state field
 
356
 
 
357
Search Criterions
 
358
#################
 
359
 
 
360
Search criterions: search available on all columns of the list view
 
361
 
 
362
Action Names
 
363
^^^^^^^^^^^^
 
364
 
 
365
.. todo:: write 'Action Names' section
 
366
 
 
367
Wizards
 
368
^^^^^^^
 
369
 
 
370
Terminology
 
371
"""""""""""
 
372
 
 
373
Default Language
 
374
^^^^^^^^^^^^^^^^
 
375
 
 
376
The default language for every development must be U.S. english.
 
377
 
 
378
For menus and fields, use uppercase for all first letters, excluding conjections:
 
379
 
 
380
  * Chart of Accounts
 
381
 
 
382
Field Naming Conventions
 
383
^^^^^^^^^^^^^^^^^^^^^^^^
 
384
 
 
385
  * Avoid generic terms in fields and use if possible explicit terms, some example:
 
386
 
 
387
    - Name -> Sale Order Name
 
388
    - Parent -> Bill of Material Parent
 
389
    - Rate -> Currency Rate Conversion
 
390
    - Amount -> Quantity Sold
 
391
 
 
392
Here are some rules to respect:
 
393
 
 
394
* many2one fields should respect this regex: '.*_id'
 
395
* one2many fields should respect this regex: '.*_ids'
 
396
* one2many relation table should respect this regex: '.*_rel'
 
397
* many2many fields should respect this regex: '.*_ids'
 
398
* use underscore to separate words
 
399
* avoid using uppercases
 
400
* if a field should be composed of several words, start by the most important words
 
401
 
 
402
   * This is good: sale_price, partner_address_id
 
403
   * This is bad: is_sellable
 
404
 
 
405
Object Naming Conventions
 
406
^^^^^^^^^^^^^^^^^^^^^^^^^
 
407
 
 
408
* All objects must start by the name of the module they are defined in.
 
409
* If an object is composed of several words, use points to separate words
 
410
 
 
411
 
 
412
 
 
413
 
 
414
Some terms
 
415
^^^^^^^^^^
 
416
 
 
417
  * All Tree of resources are called *XXX's Structure*, unless a dedicated term exist for the concept
 
418
 
 
419
    - Good: Location' Structure, Chart of Accounts, Categories' Structure
 
420
    - Bad: Tree of Category, Tree of Bill of Materials
 
421
 
 
422
Module Recorder
 
423
+++++++++++++++
 
424
 
 
425
.. todo:: write 'Module Recorder' section
 
426
 
 
427
Review quality
 
428
++++++++++++++
 
429
 
 
430
.. todo:: write 'Review quality' section
 
431