7 Odoo is greatly data-driven, and a big part of modules definition is thus
8 the definition of the various records it manages: UI (menus and views),
9 security (access rights and access rules), reports and plain data are all
15 The main way to define data in Odoo is via XML data files: The broad structure
16 of an XML data file is the following:
18 * The nested root elements ``openerp`` and ``data``
19 * Any number of operation elements within ``data``
23 <!-- the root elements of the data file -->
29 Data files are executed sequentially, operations can only refer to the result
30 of operations defined previously
35 .. _reference/data/record:
40 ``record`` appropriately defines or updates a database record, it has the
44 name of the model to create (or update)
46 the :term:`external identifier` for this record. It is strongly
47 recommended to provide one
49 * for record creation, allows subsequent definitions to either modify or
51 * for record modification, the record to modify
53 context to use when creating the record
55 in :ref:`update mode <reference/module/lifecycle/update>`, whether the
56 record should be created if it doesn't exist.
58 Requires an :term:`external id`, defaults to ``True``.
63 Each record can be composed of ``field`` tags, defining values to set when
64 creating the record. A ``record`` with no ``field`` will use all default
65 values (creation) or do nothing (update).
67 A ``field`` has a mandatory ``name`` attribute, the name of the field to set,
68 and various methods to define the value itself:
71 if no value is provided for the field, an implicit ``False`` will be set
72 on the field. Can be used to clear a field, or avoid using a default value
75 for :ref:`relational fields <reference/orm/fields/relational>`, should be
76 a :ref:`domain <reference/orm/domains>` on the field's model.
78 Will evaluate the domain, search the field's model using it and set the
79 search's result as the field's value. Will only use the first result if
80 the field is a :class:`~openerp.fields.Many2one`
82 if a ``ref`` attribute is provided, its value must be a valid
83 :term:`external id`, which will be looked up and set as the field's value.
85 Mostly for :class:`~openerp.fields.Many2one` and
86 :class:`~openerp.fields.Reference` fields
88 if a ``type`` attribute is provided, it is used to interpret and convert
89 the field's content. The field's content can be provided through an
90 external file using the ``file`` attribute, or through the node's body.
95 extracts the ``field``'s children as a single document, evaluates
96 any :term:`external id` specified with the form ``%(external_id)s``.
97 ``%%`` can be used to output actual *%* signs.
99 ensures that the field content is a valid file path in the current
100 model, saves the pair :samp:`{module},{path}` as the field value
102 sets the field content directly as the field's value without
105 base64_-encodes the field's content, useful combined with the ``file``
106 *attribute* to load e.g. image data into attachments
108 converts the field's content to an integer and sets it as the field's
111 converts the field's content to a float and sets it as the field's
114 should contain any number of ``value`` elements with the same
115 properties as ``field``, each element resolves to an item of a
116 generated tuple or list, and the generated collection is set as the
119 for cases where the previous methods are unsuitable, the ``eval``
120 attributes simply evaluates whatever Python expression it is provided and
121 sets the result as the field's value.
123 The evaluation context contains various modules (``time``, ``datetime``,
124 ``timedelta``, ``relativedelta``), a function to resolve :term:`external
125 identifiers` (``ref``) and the model object for the current field if
131 The ``delete`` tag can remove any number of records previously defined. It
132 has the following attributes:
135 the model in which a specified record should be deleted
137 the :term:`external id` of a record to remove
139 a :ref:`domain <reference/orm/domains>` to find records of the model to
142 ``id`` and ``search`` are exclusive
147 The ``function`` tag calls a method on a model, with provided parameters.
148 It has two mandatory parameters ``model`` and ``name`` specifying respectively
149 the model and the name of the method to call.
151 Parameters can be provided using ``eval`` (should evaluate to a sequence of
152 parameters to call the method with) or ``value`` elements (see ``list``
158 The ``workflow`` tag sends a signal to an existing workflow. The workflow
159 can be specified via a ``ref`` attribute (the :term:`external id` of
160 an existing workflow) or a ``value`` tag returning the id of a workflow.
162 The tag also has two mandatory attributes ``model`` (the model linked to the
163 workflow) and ``action`` (the name of the signal to send to the workflow).
170 Because some important structural models of Odoo are complex and involved,
171 data files provide shorter alternatives to defining them using
172 :ref:`record tags <reference/data/record>`:
177 Defines an ``ir.ui.menu`` record with a number of defaults and fallbacks:
180 * If a ``parent`` attribute is set, it should be the :term:`external id`
181 of an other menu item, used as the new item's parent
182 * If no ``parent`` is provided, tries to interpret the ``name`` attribute
183 as a ``/``-separated sequence of menu names and find a place in the menu
184 hierarchy. In that interpretation, intermediate menus are automatically
186 * Otherwise the menu is defined as a "top-level" menu item (*not* a menu
189 If no ``name`` attribute is specified, tries to get the menu name from
190 a linked action if any. Otherwise uses the record's ``id``
192 A ``groups`` attribute is interpreted as a comma-separated sequence of
193 :term:`external identifiers` for ``res.groups`` models. If an
194 :term:`external identifier` is prefixed with a minus (``-``), the group
195 is *removed* from the menu's groups
197 if specified, the ``action`` attribute should be the :term:`external id`
198 of an action to execute when the menu is open
200 the menu item's :term:`external id`
205 Creates a :ref:`QWeb view <reference/views/qweb>` requiring only the ``arch``
206 section of the view, and allowing a few *optional* attributes:
209 the view's :term:`external identifier`
210 ``name``, ``inherit_id``, ``priority``
211 same as the corresponding field on ``ir.ui.view`` (nb: ``inherit_id``
212 should be an :term:`external identifier`)
214 if set to ``True`` and combined with a ``inherit_id``, defines the view
217 comma-separated list of group :term:`external identifiers`
219 if set to ``"True"``, the template is a website page (linkable to,
222 ``enabled`` or ``disabled``, whether the view can be disabled (in the
223 website interface) and its default status. If unset, the view is always
229 Creates a ``ir.actions.report.xml`` record with a few default values.
231 Mostly just proxies attributes to the corresponding fields on
232 ``ir.actions.report.xml``, but also automatically creates the item in the
233 :guilabel:`More` menu of the report's ``model``.
235 .. ignored url, act_window and ir_set
240 XML data files are flexible and self-descriptive, but very verbose when
241 creating a number of simple records of the same model in bulk.
243 For this case, data files can also use csv_, this is often the case for
244 :ref:`access rights <reference/security/acl>`:
246 * the file name is :file:`{model_name}.csv`
247 * the first row lists the fields to write, with the special field ``id``
248 for :term:`external identifiers` (used for creation or update)
249 * each row thereafter creates a new record
251 Here's the first lines of the data file defining US states
252 ``res.country.state.csv``
254 .. literalinclude:: ../../openerp/addons/base/res/res.country.state.csv
258 rendered in a more readable format:
261 :file: ../../openerp/addons/base/res/res.country.state.csv
263 :class: table-striped table-hover table-condensed
265 For each row (record):
267 * the first column is the :term:`external id` of the record to create or
269 * the second column is the :term:`external id` of the country object to link
270 to (country objects must have been defined beforehand)
271 * the third column is the ``name`` field for ``res.country.state``
272 * the fourth column is the ``code`` field for ``res.country.state``
274 .. _base64: http://tools.ietf.org/html/rfc3548.html#section-3
275 .. _csv: http://en.wikipedia.org/wiki/Comma-separated_values