Odoo is greatly data-driven, and a big part of modules definition is thus the definition of the various records it manages: UI (menus and views), security (access rights and access rules), reports and plain data are all defined via records.
The main way to define data in Odoo is via XML data files: The broad structure of an XML data file is the following:
<!-- the root elements of the data file -->
<odoo>
<operation/>
...
</odoo>
Data files are executed sequentially, operations can only refer to the result of operations defined previously
record appropriately defines or updates a database record, it has the following attributes:
the external identifier for this record. It is strongly recommended to provide one
in update mode whether the record should be created if it doesn’t exist
Requires an external id, defaults to True.
Each record can be composed of field tags, defining values to set when creating the record. A record with no field will use all default values (creation) or do nothing (update).
A field has a mandatory name attribute, the name of the field to set, and various methods to define the value itself:
for relational fields, should be a domain on the field’s model.
Will evaluate the domain, search the field’s model using it and set the search’s result as the field’s value. Will only use the first result if the field is a Many2one
if a ref attribute is provided, its value must be a valid external id, which will be looked up and set as the field’s value.
Mostly for Many2one and Reference fields
if a type attribute is provided, it is used to interpret and convert the field’s content. The field’s content can be provided through an external file using the file attribute, or through the node’s body.
Available types are:
for cases where the previous methods are unsuitable, the eval attributes simply evaluates whatever Python expression it is provided and sets the result as the field’s value.
The evaluation context contains various modules (time, datetime, timedelta, relativedelta), a function to resolve external identifiers (ref) and the model object for the current field if applicable (obj)
The delete tag can remove any number of records previously defined. It has the following attributes:
id and search are exclusive
The function tag calls a method on a model, with provided parameters. It has two mandatory parameters model and name specifying respectively the model and the name of the method to call.
Parameters can be provided using eval (should evaluate to a sequence of parameters to call the method with) or value elements (see list values).
The workflow tag sends a signal to an existing workflow. The workflow can be specified via a ref attribute (the external id of an existing workflow) or a value tag returning the id of a workflow.
The tag also has two mandatory attributes model (the model linked to the workflow) and action (the name of the signal to send to the workflow).
Because some important structural models of Odoo are complex and involved, data files provide shorter alternatives to defining them using record tags:
Defines an ir.ui.menu record with a number of defaults and fallbacks:
Creates a QWeb view requiring only the arch section of the view, and allowing a few optional attributes:
Creates a ir.actions.report.xml record with a few default values.
Mostly just proxies attributes to the corresponding fields on ir.actions.report.xml, but also automatically creates the item in the More menu of the report’s model.
XML data files are flexible and self-descriptive, but very verbose when creating a number of simple records of the same model in bulk.
For this case, data files can also use csv, this is often the case for access rights:
Here’s the first lines of the data file defining US states res.country.state.csv
"id","country_id:id","name","code"
state_au_1,au,"Australian Capital Territory","ACT"
state_au_2,au,"New South Wales","NSW"
state_au_3,au,"Northern Territory","NT"
state_au_4,au,"Queensland","QLD"
state_au_5,au,"South Australia","SA"
state_au_6,au,"Tasmania","TAS"
state_au_7,au,"Victoria","VIC"
state_au_8,au,"Western Australia","WA"
state_us_1,us,"Alabama","AL"
state_us_2,us,"Alaska","AK"
state_us_3,us,"Arizona","AZ"
state_us_4,us,"Arkansas","AR"
state_us_5,us,"California","CA"
state_us_6,us,"Colorado","CO"
rendered in a more readable format:
id | country_id:id | name | code |
---|---|---|---|
state_au_1 | au | Australian Capital Territory | ACT |
state_au_2 | au | New South Wales | NSW |
state_au_3 | au | Northern Territory | NT |
state_au_4 | au | Queensland | QLD |
state_au_5 | au | South Australia | SA |
state_au_6 | au | Tasmania | TAS |
state_au_7 | au | Victoria | VIC |
state_au_8 | au | Western Australia | WA |
state_us_1 | us | Alabama | AL |
state_us_2 | us | Alaska | AK |
state_us_3 | us | Arizona | AZ |
state_us_4 | us | Arkansas | AR |
state_us_5 | us | California | CA |
state_us_6 | us | Colorado | CO |
state_us_7 | us | Connecticut | CT |
state_us_8 | us | Delaware | DE |
state_us_9 | us | District of Columbia | DC |
state_us_10 | us | Florida | FL |
state_us_11 | us | Georgia | GA |
state_us_12 | us | Hawaii | HI |
state_us_13 | us | Idaho | ID |
state_us_14 | us | Illinois | IL |
state_us_15 | us | Indiana | IN |
state_us_16 | us | Iowa | IA |
state_us_17 | us | Kansas | KS |
state_us_18 | us | Kentucky | KY |
state_us_19 | us | Louisiana | LA |
state_us_20 | us | Maine | ME |
state_us_21 | us | Montana | MT |
state_us_22 | us | Nebraska | NE |
state_us_23 | us | Nevada | NV |
state_us_24 | us | New Hampshire | NH |
state_us_25 | us | New Jersey | NJ |
state_us_26 | us | New Mexico | NM |
state_us_27 | us | New York | NY |
state_us_28 | us | North Carolina | NC |
state_us_29 | us | North Dakota | ND |
state_us_30 | us | Ohio | OH |
state_us_31 | us | Oklahoma | OK |
state_us_32 | us | Oregon | OR |
state_us_33 | us | Maryland | MD |
state_us_34 | us | Massachusetts | MA |
state_us_35 | us | Michigan | MI |
state_us_36 | us | Minnesota | MN |
state_us_37 | us | Mississippi | MS |
state_us_38 | us | Missouri | MO |
state_us_39 | us | Pennsylvania | PA |
state_us_40 | us | Rhode Island | RI |
state_us_41 | us | South Carolina | SC |
state_us_42 | us | South Dakota | SD |
state_us_43 | us | Tennessee | TN |
state_us_44 | us | Texas | TX |
state_us_45 | us | Utah | UT |
state_us_46 | us | Vermont | VT |
state_us_47 | us | Virginia | VA |
state_us_48 | us | Washington | WA |
state_us_49 | us | West Virginia | WV |
state_us_50 | us | Wisconsin | WI |
state_us_51 | us | Wyoming | WY |
For each row (record):
odoo docs theme based on Bootstrap 3.2 documentation adapted to Sphinx output with branding and color changes.