1 .. _module-dev-structure:
6 A module can contain the following elements:
8 - **Business object** : declared as Python classes extending the class
9 osv.Model, the persistence of these resource is completly managed by
11 - **Data** : XML/CSV files with meta-data (views and workflows declaration),
12 configuration data (modules parametrization) and demo data (optional but
13 recommended for testing),
14 - **Reports** : RML (XML format). HTML/MAKO or OpenOffice report templates, to
15 be merged with any kind of business data, and generate HTML, ODT or PDF
18 .. figure:: _static/03_module_gen_view.png
20 :alt: Module composition
25 Each module is contained in its own directory within either the server/bin/addons
26 directory or another directory of addons, configured in server installation.
27 To create a new module for example the 'OpenAcademy' module, the following
30 - create a ``openacademy`` subdirectory in the source/addons directory
31 - create the module import file ``__init__.py``
32 - create the module manifield file ``__openerp__.py``
33 - create **Python** files containing **objects**
34 - create **.xml files** holding module data such as views, menu entries
36 - optionally create **reports** or **workflows**
38 Python import file __init__.py
39 ++++++++++++++++++++++++++++++
41 The ``__init__.py`` file is the Python import file, because an OpenERP module
42 is also a regular Python module. The file should import all the other python
45 For example, if a module contains a single python file named ``openacademy.py``,
46 the file should look like:
50 Manifest file __openerp__.py
51 +++++++++++++++++++++++++++++++
53 In the created module directory, you must add a **__openerp__.py** file.
54 This file, which must be a Python dict literal, is responsible to
56 1. determine the *XML files that will be parsed* during the initialization
57 of the server, and also to
58 2. determine the *dependencies* of the created module.
59 3. declare additional meta data
61 This file must contain a Python dictionary with the following values:
65 name The name of the module in English.
66 version The version of the module.
67 summary Short description or keywords
68 description The module description (text).
69 category The categrory of the module
70 author The author of the module.
71 website URL of the website of the module.
72 license The license of the module (default: AGPL-3).
73 depends List of modules on which this module depends beside base.
74 data List of .xml files to load when the module is installed or updated.
75 demo List of additional .xml files to load when the module is
76 installed or updated and demo flag is active.
77 installable True or False. Determines whether the module is installable
79 auto_install True or False (default: False). If set to ``True``, the
80 module is a link module. It will be installed as soon
81 as all its dependencies are installed.
83 For the ``openacademy`` module, here is an example of ``__openerp__.py``
86 .. code-block:: python
89 'name' : "OpenAcademy",
91 'author' : "OpenERP SA",
95 'openacademy_view.xml',
96 'openacademy_data.xml',
97 'report/module_report.xml',
98 'wizard/module_wizard.xml',
101 'openacademy_demo.xml'
109 All OpenERP resources are objects: invoices, partners. Metadata are also object
110 too: menus, actions, reports... Object names are hierarchical, as in the
113 * account.transfer : a money transfer
114 * account.invoice : an invoice
115 * account.invoice.line : an invoice line
117 Generally, the first word is the name of the module: account, stock, sale.
119 Those object are declared in python be subclassing osv.Model
121 The ORM of OpenERP is constructed over PostgreSQL. It is thus possible to
122 query the object used by OpenERP using the object interface (ORM) or by
123 directly using SQL statements.
125 But it is dangerous to write or read directly in the PostgreSQL database, as
126 you will shortcut important steps like constraints checking or workflow
129 .. .. figure:: images/pom_3_0_3.png
133 .. *The Physical Objects Model of [OpenERP version 3.0.3]*
139 XML files located in the module directory are used to initialize or update the
140 the database when the module is installed or updated. They are used for many
141 purposes, among which we can cite :
143 * initialization and demonstration data declaration,
145 * reports declaration,
146 * workflows declaration.
148 General structure of OpenERP XML files is more detailed in the
149 :ref:`xml-serialization` section. Look here if you are interested in learning
150 more about *initialization* and *demonstration data declaration* XML files. The
151 following section are only related to XML specific to *actions, menu entries,
152 reports, wizards* and *workflows* declaration.
154 Data can be inserted or updated into the PostgreSQL tables corresponding to the
155 OpenERP objects using XML files. The general structure of an OpenERP XML file
160 <?xml version="1.0"?>
163 <record model="model.name_1" id="id_name_1">
164 <field name="field1"> "field1 content" </field>
165 <field name="field2"> "field2 content" </field>
168 <record model="model.name_2" id="id_name_2">
180 The addition of new data is made with the record tag. This one takes a
181 mandatory attribute : model. Model is the object name where the insertion has
182 to be done. The tag record can also take an optional attribute: id. If this
183 attribute is given, a variable of this name can be used later on, in the same
184 file, to make reference to the newly created resource ID.
186 A record tag may contain field tags. They indicate the record's fields value.
187 If a field is not specified the default value will be used.
192 The attributes for the field tag are the following:
198 python expression that indicating the value to add
201 reference to an id defined in this file
204 model to be looked up in the search
214 <record model="ir.actions.report.xml" id="l0">
215 <field name="model">account.invoice</field>
216 <field name="name">Invoices List</field>
217 <field name="report_name">account.invoice.list</field>
218 <field name="report_xsl">account/report/invoice.xsl</field>
219 <field name="report_xml">account/report/invoice.xml</field>
222 Let's review an example taken from the OpenERP source (base_demo.xml in the base module):
226 <record model="res.company" id="main_company">
227 <field name="name">Tiny sprl</field>
228 <field name="partner_id" ref="main_partner"/>
229 <field name="currency_id" ref="EUR"/>
234 <record model="res.users" id="user_admin">
235 <field name="login">admin</field>
236 <field name="password">admin</field>
237 <field name="name">Administrator</field>
238 <field name="signature">Administrator</field>
239 <field name="action_id" ref="action_menu_admin"/>
240 <field name="menu_id" ref="action_menu_admin"/>
241 <field name="address_id" ref="main_address"/>
242 <field name="groups_id" eval="[(6,0,[group_admin])]"/>
243 <field name="company_id" ref="main_company"/>
246 This last record defines the admin user :
248 * The fields login, password, etc are straightforward.
249 * The ref attribute allows to fill relations between the records :
253 <field name="company_id" ref="main_company"/>
255 The field **company_id** is a many-to-one relation from the user object to the company object, and **main_company** is the id of to associate.
257 * The **eval** attribute allows to put some python code in the xml: here the groups_id field is a many2many. For such a field, "[(6,0,[group_admin])]" means : Remove all the groups associated with the current user and use the list [group_admin] as the new associated groups (and group_admin is the id of another record).
259 * The **search** attribute allows to find the record to associate when you do not know its xml id. You can thus specify a search criteria to find the wanted record. The criteria is a list of tuples of the same form than for the predefined search method. If there are several results, an arbitrary one will be chosen (the first one):
263 <field name="partner_id" search="[]" model="res.partner"/>
265 This is a classical example of the use of **search** in demo data: here we do not really care about which partner we want to use for the test, so we give an empty list. Notice the **model** attribute is currently mandatory.
270 A function tag can contain other function tags.
276 the function given name
279 should evaluate to the list of parameters of the method to be called, excluding cr and uid
285 <function model="ir.ui.menu" name="search" eval="[[('name','=','Operations')]]"/>
291 Views are a way to represent the objects on the client side. They indicate to the client how to lay out the data coming from the objects on the screen.
293 There are two types of views:
298 Lists are simply a particular case of tree views.
300 A same object may have several views: the first defined view of a kind (*tree, form*, ...) will be used as the default view for this kind. That way you can have a default tree view (that will act as the view of a one2many) and a specialized view with more or less information that will appear when one double-clicks on a menu item. For example, the products have several views according to the product variants.
302 Views are described in XML.
304 If no view has been defined for an object, the object is able to generate a view to represent itself. This can limit the developer's work but results in less ergonomic views.
310 When you open an invoice, here is the chain of operations followed by the client:
312 * An action asks to open the invoice (it gives the object's data (account.invoice), the view, the domain (e.g. only unpaid invoices) ).
313 * The client asks (with XML-RPC) to the server what views are defined for the invoice object and what are the data it must show.
314 * The client displays the form according to the view
316 .. .. figure:: images/arch_view_use.png
320 To develop new objects
321 //////////////////////
323 The design of new objects is restricted to the minimum: create the objects and optionally create the views to represent them. The PostgreSQL tables do not have to be written by hand because the objects are able to automatically create them (or adapt them in case they already exist).
328 OpenERP uses a flexible and powerful reporting system. Reports are generated either in PDF or in HTML. Reports are designed on the principle of separation between the data layer and the presentation layer.
330 Reports are described more in details in the `Reporting <http://openobject.com/wiki/index.php/Developers:Developper%27s_Book/Reports>`_ chapter.
336 The objects and the views allow you to define new forms very simply, lists/trees and interactions between them. But that is not enough, you must define the dynamics of these objects.
340 * a confirmed sale order must generate an invoice, according to certain conditions
341 * a paid invoice must, only under certain conditions, start the shipping order
343 The workflows describe these interactions with graphs. One or several workflows may be associated to the objects. Workflows are not mandatory; some objects don't have workflows.
345 Below is an example workflow used for sale orders. It must generate invoices and shipments according to certain conditions.
347 .. .. figure:: images/arch_workflow_sale.png
352 In this graph, the nodes represent the actions to be done:
355 * cancel the sale order,
356 * generate the shipping order, ...
358 The arrows are the conditions;
360 * waiting for the order validation,
362 * click on the cancel button, ...
364 The squared nodes represent other Workflows;
373 .. versionchanged:: 5.0
375 Each module has its own ``i18n`` folder. In addition, OpenERP can now deal with
376 ``.po`` [#f_po]_ files as import/export format. The translation files of the
377 installed languages are automatically loaded when installing or updating a
380 Translations are managed by the `Launchpad Web interface
381 <https://translations.launchpad.net/openobject>`_. Here, you'll find the list
382 of translatable projects.
384 Please read the `FAQ <https://answers.launchpad.net/rosetta/+faqs>`_ before asking questions.
387 .. [#f_po] http://www.gnu.org/software/autoconf/manual/gettext/PO-Files.html#PO-Files